Class: Cuprum::Cli::Commands::File::GenerateFile
- Parent Namespace
- Cuprum::Cli::Commands::File
- Inherited Classes
- Cuprum::Command
>
Object
- Extended Modules
- Cuprum::Cli::Options::ClassMethods
- Included Modules
- Cuprum::Cli::Dependencies::StandardIo::Helpers, Cuprum::Cli::Options::Quiet, Cuprum::Cli::Options::Verbose, Plumbum::Consumer, Plumbum::Parameters
- Defined In
- lib/cuprum/cli/commands/file/generate_file.rb
Table Of Contents
Overview
Utility command for generating a file from a template.
Back To Top
Constants
FALSY_VALUES
= Set.new(%w[f false n no]).freeze
- Inherited From
- Cuprum::Cli::Dependencies::StandardIo::Helpers
String input values that will be mapped to a boolean false.
INTEGER_PATTERN
= /\A-?\d+([\d_,]+\d)?\z/
- Inherited From
- Cuprum::Cli::Dependencies::StandardIo::Helpers
Pattern matching a valid integer input.
TRUTHY_VALUES
= Set.new(%w[t true y yes]).freeze
- Inherited From
- Cuprum::Cli::Dependencies::StandardIo::Helpers
String input values that will be mapped to a boolean true.
Back To Top
Class Methods
.option(name, aliases: [], default: nil, description: nil, required: false, type: :string, **options) => Object
- Inherited From
- Cuprum::Cli::Options::ClassMethods
Defines an option for the command class.
Parameters
- name (String, Symbol) — the name of the option.
- aliases (Array<String, Symbol>) — aliases for the option when
parsing options from the command line.
- default (Object, Proc) — the default value for the option. If given
and the value of the option is nil, sets the option value to the
default value.
- description (String) — a short, human-readable description of the
option.
- required (true, false) — if true, raises an exception if the option
is not provided to the command.
- type (Class, String, Symbol) — the expected type of the option
value as a Class or class name. If given, raises an exception if the
option value is not an instance of the type. Defaults to :string.
- options (Hash) — additional options for defining the option.
Options Hash (options)
- define_method (true, false) — if true, defines a reader
method for the option. Defaults to false for boolean options and true
for all other options.
- define_predicate (true, false) — if true, defines a
predicate method for the option, which returns true if the option is
not nil and not empty. Defaults to true for boolean options and false
for all other options.
.option_value(option, value) => void
- Inherited From
- Cuprum::Cli::Options::ClassMethods
Assigns a predefined option value for the command.
Parameters
- option (String, Symbol) — the option to set.
- value (Object) — the option value to append.
Returns
.option_values => Hash{Symbol => Object}
- Inherited From
- Cuprum::Cli::Options::ClassMethods
Returns
- (Hash{Symbol => Object}) — predefined option values for the command.
- Inherited From
- Cuprum::Cli::Options::ClassMethods
The defined options, including options defined on ancestor classes.
Returns
.resolve_options(**values) => Hash
- Inherited From
- Cuprum::Cli::Options::ClassMethods
Validates the given option values against the defined class options.
Also applies any default values from the defined options.
Parameters
- values (Hash) — the option values to resolve.
Returns
- (Hash) — the option values with applied defaults.
Raises
Back To Top
Constructor
#initialize(**options) => Object
Overloads
#initialize(**options) => Object
Parameters
- options (Hash) — options for initializing the command.
Returns
- (GenerateFile) — a new instance of GenerateFile
Back To Top
Instance Methods
#ask(prompt = nil, caret: true, format: nil, strip: true, **options) => String, Integer, true, false, nil
- Inherited From
- Cuprum::Cli::Dependencies::StandardIo::Helpers
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
- Inherited From
- Cuprum::Cli::Options::Verbose
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
- Inherited From
- Cuprum::Cli::Dependencies::StandardIo::Helpers
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::Commands
|
Cuprum::Cli::Commands::File