lib/git_commands/prompt.rb in git_commands-3.0.5 vs lib/git_commands/prompt.rb in git_commands-3.1.6
- old
+ new
@@ -3,53 +3,47 @@
module GitCommands
using Colorize
module Prompt
VALID_ANSWERS = %w[Y y N n]
+ class AbortError < StandardError; end
+
def out
@out ||= STDOUT
end
- def warning(message, char = "*")
- spacer = (char * (message.size + 4)).grey
- out.puts "\n", spacer, "#{char} #{message.to_s.yellow} #{char}", spacer, "\n"
+ def warning(message)
+ out.puts "\n#{message}...".yellow
end
- def error(message, error = StandardError)
- out.puts message.to_s.red
- yield if block_given?
- fail error, message
- end
-
def success(message)
out.puts message.to_s.green
+ true
end
def confirm(message)
res = begin
ask "#{message} (Y/N)?"
end until VALID_ANSWERS.include?(res)
case res
when /y/i
yield
else
- abort!("Aborted operation!")
+ fail(AbortError, "Aborted operation!")
end
end
- private
-
- def ask(message)
- out.print message.cyan
- input
- end
-
- def abort!(message)
+ def error(message)
out.puts message.to_s.red
exit
end
- def input
+ private def ask(message)
+ out.print message.cyan
+ input
+ end
+
+ private def input
STDIN.gets.chomp
end
end
end