Module: Cuprum::Cli::Dependencies::StandardIo::Helpers
- Included in:
- Commands::Ci::RSpecCommand, Commands::Ci::RSpecEachCommand, Commands::File::GenerateFile
- Defined in:
- lib/cuprum/cli/dependencies/standard_io/helpers.rb
Overview
Helper methods for reading from and writing to standard inputs and outputs.
Constant Summary collapse
- FALSY_VALUES =
String input values that will be mapped to a boolean false.
Set.new(%w[f false n no]).freeze
- INTEGER_PATTERN =
Pattern matching a valid integer input.
/\A-?\d+([\d_,]+\d)?\z/- TRUTHY_VALUES =
String input values that will be mapped to a boolean true.
Set.new(%w[t true y yes]).freeze
Instance Method Summary collapse
-
#ask(prompt = nil, caret: true, format: nil, strip: true, **options) ⇒ String, ...
Requests an input from the input stream.
-
#say(message, newline: true, quiet: false, verbose: false, **options) ⇒ nil
Prints a message to the output stream.
-
#warn(message, **options) ⇒ nil
Prints a message to the error stream.
Instance Method Details
#ask(prompt = nil, caret: true, format: nil, strip: true, **options) ⇒ String, ...
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/cuprum/cli/dependencies/standard_io/helpers.rb', line 37 def ask( # rubocop:disable Metrics/ParameterLists prompt = nil, caret: nil, format: nil, newline: true, strip: true, ** ) validate_prompt(prompt) display_prompt(caret:, newline:, prompt:) value = standard_io.read_input&.then { |str| strip ? str.strip : str } return if value.nil? || value.empty? return value if format.nil? send(:"format_#{format}", value) end |
#say(message, newline: true, quiet: false, verbose: false, **options) ⇒ nil
73 74 75 76 77 |
# File 'lib/cuprum/cli/dependencies/standard_io/helpers.rb', line 73 def say(, newline: true, **) () standard_io.write_output(, newline:) end |
#warn(message, **options) ⇒ nil
89 90 91 92 93 |
# File 'lib/cuprum/cli/dependencies/standard_io/helpers.rb', line 89 def warn(, newline: true, **) () standard_io.write_error(, newline:) end |