Module: Aspera::Cli::Prompt
- Included in:
- Parser
- Defined in:
- lib/aspera/cli/prompt.rb
Overview
Console input
Instance Method Summary collapse
-
#prompt_user_input(prompt, sensitive: false) ⇒ String
Prompt user for console input.
-
#prompt_user_input_in_list(prompt, sym_list) ⇒ Symbol
Prompt user for input in a list of symbols.
Instance Method Details
#prompt_user_input(prompt, sensitive: false) ⇒ String
Prompt user for console input
14 15 16 17 18 19 20 |
# File 'lib/aspera/cli/prompt.rb', line 14 def prompt_user_input(prompt, sensitive: false) return $stdin.getpass("#{prompt}> ") if sensitive print("#{prompt}> ") line = $stdin.gets Aspera.assert_type(line, String) { 'Unexpected end of standard input' } line.chomp end |
#prompt_user_input_in_list(prompt, sym_list) ⇒ Symbol
Prompt user for input in a list of symbols
26 27 28 29 30 31 32 |
# File 'lib/aspera/cli/prompt.rb', line 26 def prompt_user_input_in_list(prompt, sym_list) loop do input = prompt_user_input(prompt).to_sym return input if sym_list.any? { |a| a.eql?(input) } $stderr.puts("No such #{prompt}: #{input}, select one of: #{sym_list.join(', ')}") # rubocop:disable Style/StderrPuts end end |