diff --git a/lib/mono.rb b/lib/mono.rb index 1182f6f..f925d04 100644 --- a/lib/mono.rb +++ b/lib/mono.rb @@ -39,6 +39,7 @@ def message end end +require "mono/shell" require "mono/version" require "mono/version_object" require "mono/version_promoter" diff --git a/lib/mono/cli.rb b/lib/mono/cli.rb index ed838ee..513c1ed 100644 --- a/lib/mono/cli.rb +++ b/lib/mono/cli.rb @@ -6,40 +6,8 @@ module Mono module Cli - module Helpers - def ask_for_input - value = $stdin.gets - value ? value.chomp : "" - rescue Interrupt - puts "\nExiting..." - exit 1 - end - - def required_input(prompt) - loop do - print prompt - value = ask_for_input - return value unless value.empty? - end - end - - def yes_or_no(prompt, options = {}) - loop do - print prompt - input = ask_for_input.strip - input = options[:default] if input.empty? && options[:default] - case input - when "y", "Y", "yes" - return true - when "n", "N", "no" - return false - end - end - end - end - class Base - include Helpers + include Shell include Command::Helper def initialize(options = {}) diff --git a/lib/mono/cli/init.rb b/lib/mono/cli/init.rb index 7822a64..6b28428 100644 --- a/lib/mono/cli/init.rb +++ b/lib/mono/cli/init.rb @@ -3,7 +3,7 @@ module Mono module Cli class Init - include Helpers + include Shell def execute config = {} diff --git a/lib/mono/shell.rb b/lib/mono/shell.rb new file mode 100644 index 0000000..4e63eae --- /dev/null +++ b/lib/mono/shell.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +module Mono + module Shell + module_function + + def ask_for_input + value = $stdin.gets + value ? value.chomp : "" + rescue Interrupt + puts "\nExiting..." + exit 1 + end + + def required_input(prompt) + loop do + print prompt + value = ask_for_input + return value unless value.empty? + end + end + + def yes_or_no(prompt, options = {}) + loop do + print prompt + input = ask_for_input.strip + input = options[:default] if input.empty? && options[:default] + case input + when "y", "Y", "yes" + return true + when "n", "N", "no" + return false + end + end + end + end +end