Module: Cuprum::Cli::Dependencies::StandardIo::Helpers
- Parent Namespace
- Cuprum::Cli::Dependencies::StandardIo
- Defined In
- lib/cuprum/cli/dependencies/standard_io/helpers.rb
Table Of Contents
Overview
Helper methods for reading from and writing to standard inputs and outputs.
Back To Top
Constants
FALSY_VALUES
= Set.new(%w[f false n no]).freeze
String input values that will be mapped to a boolean false.
INTEGER_PATTERN
= /\A-?\d+([\d_,]+\d)?\z/
Pattern matching a valid integer input.
TRUTHY_VALUES
= Set.new(%w[t true y yes]).freeze
String input values that will be mapped to a boolean true.
Back To Top
Instance Methods
#ask(prompt = nil, caret: true, format: nil, strip: true, **options) => String, Integer, true, false, nil
Requests an input from the input stream.
Parameters
- prompt (String, nil) — the prompt to display to the user, if any.
- options (Hash) — options for requesting the input.
Options Hash (options)
- caret (true, false) — if true, prints a caret "> " to the
output stream after the prompt. Defaults to true when the newline
option is true, otherwise false.
- format (String, Symbol) — the expected format of the
input. Valid values are :string (the default), :boolean, and :integer.
The input string will be transformed into the given format, or an
exception raised if the value cannot be transformed.
- newline (true, false) — if true, a newline will be printed
after the prompt if a prompt is given.
- strip (true, false) — if true, strips the trailing newline
from the input. Defaults to true.
Returns
- (String, Integer, true, false, nil) — the received and formatted
input value, or nil if the input value was empty.
#say(message, newline: true, quiet: false, verbose: false, **options) => nil
Prints a message to the output stream.
Parameters
- message (String) — the message to print.
- options (Hash) — options for printing the message.
Options Hash (options)
- newline (true, false) — if true, appends a newline to the
message if the message does not end with a newline. Defaults to true.
- quiet (true, false) — if true, prints the message even if
the command has the :quiet option enabled. Defaults to false. Ignored
if
the command does not support the :quiet option.
- verbose (true, false) — if true, prints the message only
if the command has the :verbose option enabled. Defaults to false.
Ignored if the command does not support the :verbose option.
Returns
#warn(message, **options) => nil
Prints a message to the error stream.
Parameters
- message (String) — the message to print.
- options (Hash) — options for printing the message.
Options Hash (options)
- newline (true, false) — if true, appends a newline to the
message if the message does not end with a newline. Defaults to true.
Returns
Back To Top
Back to
Documentation |
Reference
|
Cuprum
|
Cuprum::Cli
|
Cuprum::Cli::Dependencies
|
Cuprum::Cli::Dependencies::StandardIo