abstract class Cli::CommandBase
- Cli::CommandBase
- Reference
- Object
Overview
The base of command classes.
Your application should not directly inherit this class. Instead, use Command
or Supercommand
.
Direct Known Subclasses
Defined in:
lib/command_base.crlib/command_base/macros.cr
Class Method Summary
-
.command_name(value : String)
Sets the command name.
-
.disable_help_on_parsing_error!
Disables printing a help message when a parsing error occurs.
-
.generate_bash_completion
Generates a bash completion script.
-
.generate_zsh_completion(functional : Bool = true)
Generates a zsh completion script.
-
.version(value : String)
Sets the command version.
Instance Method Summary
-
#args
Returns option and argument values (an
OptionModel
instance). -
#err
Returns the :err IO.
-
#error!(message : String | Nil = nil, code : Int32 | Nil = nil, help : Bool = false, indent = 2)
Exits the command with an error status.
-
#exit!(message : String | Nil = nil, error : Bool = false, code : Int32 | Nil = nil, help = false, indent = 2)
Exits the command.
-
#help!(message : String | Nil = nil, error : Bool | Nil = nil, code : Int32 | Nil = nil, indent = 2)
Prints a help message and exits the command.
-
#io
Returns a named IO container.
-
#nameless_args : Array(String)
Returns an array of nameless argument values.
-
#options
Returns option and argument values (an
OptionModel
instance). -
#out
Returns the :out IO.
-
#print(*args)
Invokes the :out IO'S print method.
-
#puts(*args)
Invokes the :out IO's puts method.
-
#run
Runs the command.
-
#unparsed_args : Array(String)
Returns an array of unparsed argument values.
-
#version : String
Returns the command version.
-
#version!
Prints a version string and exits the command.
-
#version? : String | Nil
Returns the command version.
Macro Summary
-
define_callback_group(name, proc_type = ::Proc(::Nil))
Defines a new callback group.
-
inherit_callback_group(name, proc_type = ::Proc(::Nil))
Inherits an existing callback group that is defined in its ancestor class.
-
replacer_command(klass)
Replaces this command with the klass command.
Class Method Detail
Disables printing a help message when a parsing error occurs.
Instance Method Detail
Returns option and argument values (an OptionModel
instance).
This method is the same as #options
.
Exits the command with an error status.
Exits the command.
Prints a help message and exits the command.
Returns an array of nameless argument values.
This method is a short form of #args
.nameless_args.
Returns option and argument values (an OptionModel
instance).
This method is the same as #args
.
Runs the command.
This method is an entrypoint for running a command.
Subclasses must override this method.
Returns an array of unparsed argument values.
This method is a short form of #args
.unparsed_args.
Macro Detail
Defines a new callback group.
This macro is automatically defined by the Crystal Callback library.
Inherits an existing callback group that is defined in its ancestor class.
This macro is automatically defined by the Crystal Callback library.