Module: StackMaster::Prompter

Included in:
Commands::Apply, Commands::Delete
Defined in:
lib/stack_master/prompter.rb

Instance Method Summary collapse

Instance Method Details

#ask?(question) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/stack_master/prompter.rb', line 5

def ask?(question)
  StackMaster.stdout.print question
  answer = if StackMaster.interactive?
    if StackMaster.stdin.tty? && StackMaster.stdout.tty?
      StackMaster.stdin.getch.chomp
    else
      StackMaster.stdout.puts
      StackMaster.stdout.puts "STDOUT or STDIN was not a TTY. Defaulting to no. To force yes use -y"
      'n'
    end
  else
    print StackMaster.non_interactive_answer
    StackMaster.non_interactive_answer
  end
  StackMaster.stdout.puts
  answer == 'y'
end