Class | Cri::Command |
In: |
lib/cri/command.rb
|
Parent: | Object |
Cri::Command represents a command that can be executed on the commandline. It is also used for the commandline tool itself.
commands | -> | subcommands |
hidden | -> | hidden? |
aliases | [RW] |
@return [Array<String>] A list of
aliases for this command that can be
used to invoke this command |
block | [RW] |
@return [Proc] The block that should be executed when invoking this
command (ignored for commands with subcommands) |
commands | [RW] | @return [Set<Cri::Command>] This command’s subcommands |
description | [RW] | @return [String] The long description (“description”) |
hidden | [RW] |
@return [Boolean] true if the command is hidden (e.g. because it is
deprecated), false otherwise |
name | [RW] | @return [String] The name |
option_definitions | [RW] | @return [Array<Hash>] The list of option definitions |
summary | [RW] | @return [String] The short description (“summary”) |
supercommand | [RW] |
@return [Cri::Command, nil] This command’s
supercommand, or nil if the
command has no supercommand |
usage | [RW] |
@return [String] The usage, without the
“usage:” prefix and without the
supercommands’ names. |
Creates a new command using the DSL. If a string is given, the command will be defined using the string; if a block is given, the block will be used instead.
If the block has one parameter, the block will be executed in the same context with the command DSL as its parameter. If the block has no parameters, the block will be executed in the context of the DSL.
@param [String, nil] string The command definition as a string
@param [String, nil] filename The filename corresponding to the string parameter (only useful if a string is given)
@return [Cri::Command] The newly defined command
Returns a new command that implements showing help.
@return [Cri::Command] A basic help command
Returns a new command that has support for the `-h`/`—help` option and also has a `help` subcommand. It is intended to be modified (adding name, summary, description, other subcommands, …)
@return [Cri::Command] A basic root command
Adds the given command as a subcommand to the current command.
@param [Cri::Command] command The command to add as a subcommand
@return [void]
Returns the command with the given name. This method will display error messages and exit in case of an error (unknown or ambiguous command).
The name can be a full command name, a partial command name (e.g. “com” for “commit”) or an aliased command name (e.g. “ci” for “commit”).
@param [String] name The full, partial or aliases name of the command
@return [Cri::Command] The command with the given name
Returns the commands that could be referred to with the given name. If the result contains more than one command, the name is ambiguous.
@param [String] name The full, partial or aliases name of the command
@return [Array<Cri::Command>] A list of commands matching the given name
Defines a new subcommand for the current command using the DSL.
@param [String, nil] name The name of the subcommand, or nil if no name
should be set (yet)
@return [Cri::Command] The subcommand
Modifies the command using the DSL.
If the block has one parameter, the block will be executed in the same context with the command DSL as its parameter. If the block has no parameters, the block will be executed in the context of the DSL.
@return [Cri::Command] The command itself
Runs the command with the given commandline arguments, possibly invoking subcommands and passing on the options and arguments.
@param [Array<String>] opts_and_args A list of unparsed arguments
@param [Hash] parent_opts A hash of options already handled by the
supercommand
@return [void]
Runs the actual command with the given commandline arguments, not invoking any subcommands. If the command does not have an execution block, an error ir raised.
@param [Array<String>] opts_and_args A list of unparsed arguments
@param [Hash] parent_opts A hash of options already handled by the
supercommand
@raise [NotImplementedError] if the command does not have an execution
block
@return [void]