Module: GitCommands::Prompt

Included in:
CLI, Computer
Defined in:
lib/git_commands/prompt.rb

Defined Under Namespace

Classes: AbortError

Constant Summary collapse

VALID_ANSWERS =
%w[Y y N n]

Instance Method Summary collapse

Instance Method Details

#confirm(message) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/git_commands/prompt.rb', line 23

def confirm(message)
  res = begin
    ask "#{message} (Y/N)?"
  end until VALID_ANSWERS.include?(res)
  case res
  when /y/i
    yield
  else
    fail(AbortError, "Aborted operation!")
  end
end

#error(message) ⇒ Object



35
36
37
# File 'lib/git_commands/prompt.rb', line 35

def error(message)
  out.puts message.to_s.red
end

#outObject



10
11
12
# File 'lib/git_commands/prompt.rb', line 10

def out
  @out ||= STDOUT
end

#success(message) ⇒ Object



18
19
20
21
# File 'lib/git_commands/prompt.rb', line 18

def success(message)
  out.puts "\n#{message}".green
  true
end

#warning(message) ⇒ Object



14
15
16
# File 'lib/git_commands/prompt.rb', line 14

def warning(message)
  out.puts "\n#{message}".yellow
end