abstract class Cling::Command
- Cling::Command
- Reference
- Object
Direct Known Subclasses
Defined in:
cling/command.crConstructors
Instance Method Summary
-
#add_alias(name : String) : Nil
Adds an alias to the command.
-
#add_aliases(*names : String) : Nil
Adds several aliases to the command.
-
#add_argument(name : String, *, description : String | Nil = nil, required : Bool = false, multiple : Bool = false) : Nil
Adds an argument to the command.
-
#add_command(command : Command) : Nil
Adds a command as a subcommand to the parent.
-
#add_commands(*commands : Command) : Nil
Adds several commands as subcommands to the parent (see
#add_command
). -
#add_option(short : Char, long : String, *, description : String | Nil = nil, required : Bool = false, type : Option::Type = :none, default : Value::Type = nil) : Nil
Adds a short flag option to the command.
-
#add_option(long : String, *, description : String | Nil = nil, required : Bool = false, type : Option::Type = :none, default : Value::Type = nil) : Nil
Adds a long flag option to the command.
-
#add_usage(usage : String) : Nil
Adds a usage string to the command.
-
#aliases : Set(String)
A set of aliases for the command.
-
#arguments : Hash(String, Argument)
A hash of arguments belonging to the command.
-
#children : Hash(String, Command)
A hash of commands that belong and inherit from the parent command.
-
#description : String | Nil
The description of the command to show for specific help with the command.
-
#description=(description : String | Nil)
The description of the command to show for specific help with the command.
-
#execute(input : String | Array(String), *, parser : Parser | Nil = nil) : Nil
Executes the command with the given input and parser (see
Parser
). -
#footer : String | Nil
A footer message to display at the bottom of generated help templates.
-
#footer=(footer : String | Nil)
A footer message to display at the bottom of generated help templates.
-
#header : String | Nil
A header message to display at the top of generated help templates.
-
#header=(header : String | Nil)
A header message to display at the top of generated help templates.
-
#help_template : String
Returns the help template for this command.
-
#hidden=(hidden : Bool)
Whether the command should be hidden from generated help templates.
-
#hidden? : Bool
Whether the command should be hidden from generated help templates.
- #inherit_borders=(inherit_borders : Bool)
- #inherit_borders? : Bool
-
#inherit_options=(inherit_options : Bool)
Whether the command should inherit the options from the parent command.
-
#inherit_options? : Bool
Whether the command should inherit the options from the parent command.
-
#inherit_streams=(inherit_streams : Bool)
Whether the command should inherit the IO streams from the parent command.
-
#inherit_streams? : Bool
Whether the command should inherit the IO streams from the parent command.
-
#is?(name : String) : Bool
Returns
true
if the argument matches the command name or any aliases. -
#name : String
The name of the command.
- #name=(name : String)
-
#on_error(ex : Exception)
A hook method for when the command raises an exception during execution.
-
#on_missing_arguments(arguments : Array(String))
A hook method for when the command receives missing arguments during execution.
-
#on_missing_options(options : Array(String))
A hook method for when the command receives missing options that are required during execution.
-
#on_unknown_arguments(arguments : Array(String))
A hook method for when the command receives unknown arguments during execution.
-
#on_unknown_options(options : Array(String))
A hook method for when the command receives unknown options during execution.
-
#options : Hash(String, Option)
A hash of flag options belonging to the command.
-
#parent : Command | Nil
The parent of the command of which the current command inherits from.
-
#parent=(parent : Command | Nil)
The parent of the command of which the current command inherits from.
- #post_run(arguments : Arguments, options : Options) : Nil
-
#pre_run(arguments : Arguments, options : Options) : Bool | Nil
A hook method to run once the command/subcommands, arguments and options have been parsed.
-
#run(arguments : Arguments, options : Options) : Nil
The main point of execution for the command, where arguments and options can be accessed.
-
#setup : Nil
An abstract method that should define information about the command such as the name, aliases, arguments, options, etc.
-
#stderr : IO
The standard error stream for commands (defaults to
STDERR
). -
#stderr=(stderr : IO)
The standard error stream for commands (defaults to
STDERR
). -
#stdin : IO
The standard input stream for commands (defaults to
STDIN
). -
#stdin=(stdin : IO)
The standard input stream for commands (defaults to
STDIN
). -
#stdout : IO
The standard output stream for commands (defaults to
STDOUT
). -
#stdout=(stdout : IO)
The standard output stream for commands (defaults to
STDOUT
). -
#summary : String | Nil
The summary of the command to show in generated help templates.
-
#summary=(summary : String | Nil)
The summary of the command to show in generated help templates.
-
#usage : Array(String)
An array of usage strings to display in generated help templates.
Constructor Detail
Instance Method Detail
Adds an argument to the command.
Adds a command as a subcommand to the parent. The command can then be referenced by specifying it as the first argument in the command line.
Adds several commands as subcommands to the parent (see #add_command
).
Adds a short flag option to the command.
Adds a long flag option to the command.
A hash of arguments belonging to the command. These arguments are parsed at execution time
and can be accessed in the #pre_run
, #run
, and #post_run
methods via ArgumentsInput
.
A hash of commands that belong and inherit from the parent command.
The description of the command to show for specific help with the command.
The description of the command to show for specific help with the command.
Executes the command with the given input and parser (see Parser
).
A header message to display at the top of generated help templates.
Returns the help template for this command. By default, one is generated interally unless this method is overridden.
Whether the command should inherit the options from the parent command.
Whether the command should inherit the options from the parent command.
Whether the command should inherit the IO streams from the parent command.
Whether the command should inherit the IO streams from the parent command.
Returns true
if the argument matches the command name or any aliases.
The name of the command. This is the only required field of a command and cannot be empty or blank.
A hook method for when the command raises an exception during execution. By default, this raises the exception.
A hook method for when the command receives missing arguments during execution. By default,
this raises an ArgumentError
.
A hook method for when the command receives missing options that are required during
execution. By default, this raises an ArgumentError
.
A hook method for when the command receives unknown arguments during execution. By default,
this raises an ArgumentError
.
A hook method for when the command receives unknown options during execution. By default,
this raises an ArgumentError
.
A hash of flag options belonging to the command. These options are parsed at execution time
and can be accessed in the #pre_run
, #run
, and #post_run
methods via OptionsInput
.
The parent of the command of which the current command inherits from.
The parent of the command of which the current command inherits from.
A hook method to run once the command/subcommands, arguments and options have been parsed.
This has access to the parsed arguments and options from the command line. This is useful if
you want to implement checks for specific flags outside of the main #run
method, such as
-v
/--version
flags or -h
/--help
flags.
Accepts a Bool
or nil
argument as a return to specify whether the command should continue
to run once finished (true
or nil
to continue, false
to stop).
The main point of execution for the command, where arguments and options can be accessed.
An abstract method that should define information about the command such as the name, aliases, arguments, options, etc. The command name is required for all commands, all other values are optional including the help message.
The standard error stream for commands (defaults to STDERR
). This is a helper method for
custom commands and is only used by the MainCommand
helper class.
The standard error stream for commands (defaults to STDERR
). This is a helper method for
custom commands and is only used by the MainCommand
helper class.
The standard input stream for commands (defaults to STDIN
). This is a helper method for
custom commands and is only used by the MainCommand
helper class.
The standard input stream for commands (defaults to STDIN
). This is a helper method for
custom commands and is only used by the MainCommand
helper class.
The standard output stream for commands (defaults to STDOUT
). This is a helper method for
custom commands and is only used by the MainCommand
helper class.
The standard output stream for commands (defaults to STDOUT
). This is a helper method for
custom commands and is only used by the MainCommand
helper class.
The summary of the command to show in generated help templates.