abstract class Cling::Command

Direct Known Subclasses

Defined in:

cling/command.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(*, aliases : Set(String) | Nil = nil, usage : Array(String) | Nil = nil, header : String | Nil = nil, summary : String | Nil = nil, description : String | Nil = nil, footer : String | Nil = nil, parent : Command | Nil = nil, children : Array(Command) | Nil = nil, arguments : Hash(String, Argument) | Nil = nil, options : Hash(String, Option) | Nil = nil, hidden : Bool = false, inherit_borders : Bool = false, inherit_options : Bool = false, inherit_streams : Bool = false, stdin : IO = STDIN, stdout : IO = STDOUT, stderr : IO = STDERR) #

[View source]

Instance Method Detail

def add_alias(name : String) : Nil #

Adds an alias to the command.


[View source]
def add_aliases(*names : String) : Nil #

Adds several aliases to the command.


[View source]
def add_argument(name : String, *, description : String | Nil = nil, required : Bool = false, multiple : Bool = false) : Nil #

Adds an argument to the command.


[View source]
def add_command(command : Command) : Nil #

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.


[View source]
def add_commands(*commands : Command) : Nil #

Adds several commands as subcommands to the parent (see #add_command).


[View source]
def 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.


[View source]
def 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.


[View source]
def add_usage(usage : String) : Nil #

Adds a usage string to the command.


[View source]
def aliases : Set(String) #

A set of aliases for the command.


[View source]
def arguments : Hash(String, Argument) #

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.


[View source]
def children : Hash(String, Command) #

A hash of commands that belong and inherit from the parent command.


[View source]
def description : String | Nil #

The description of the command to show for specific help with the command.


[View source]
def description=(description : String | Nil) #

The description of the command to show for specific help with the command.


[View source]
def execute(input : String | Array(String), *, parser : Parser | Nil = nil) : Nil #

Executes the command with the given input and parser (see Parser).


[View source]
def footer : String | Nil #

A footer message to display at the bottom of generated help templates.


[View source]
def footer=(footer : String | Nil) #

A footer message to display at the bottom of generated help templates.


[View source]
def header : String | Nil #

A header message to display at the top of generated help templates.


[View source]
def header=(header : String | Nil) #

A header message to display at the top of generated help templates.


[View source]
def help_template : String #

Returns the help template for this command. By default, one is generated interally unless this method is overridden.


[View source]
def hidden=(hidden : Bool) #

Whether the command should be hidden from generated help templates.


[View source]
def hidden? : Bool #

Whether the command should be hidden from generated help templates.


[View source]
def inherit_borders=(inherit_borders : Bool) #

Whether the command should inherit the #header and #footer strings from the parent command.


[View source]
def inherit_borders? : Bool #

Whether the command should inherit the #header and #footer strings from the parent command.


[View source]
def inherit_options=(inherit_options : Bool) #

Whether the command should inherit the options from the parent command.


[View source]
def inherit_options? : Bool #

Whether the command should inherit the options from the parent command.


[View source]
def inherit_streams=(inherit_streams : Bool) #

Whether the command should inherit the IO streams from the parent command.


[View source]
def inherit_streams? : Bool #

Whether the command should inherit the IO streams from the parent command.


[View source]
def is?(name : String) : Bool #

Returns true if the argument matches the command name or any aliases.


[View source]
def name : String #

The name of the command. This is the only required field of a command and cannot be empty or blank.


[View source]
def name=(name : String) #

[View source]
def on_error(ex : Exception) #

A hook method for when the command raises an exception during execution. By default, this raises the exception.


[View source]
def on_missing_arguments(arguments : Array(String)) #

A hook method for when the command receives missing arguments during execution. By default, this raises an ArgumentError.


[View source]
def on_missing_options(options : Array(String)) #

A hook method for when the command receives missing options that are required during execution. By default, this raises an ArgumentError.


[View source]
def on_unknown_arguments(arguments : Array(String)) #

A hook method for when the command receives unknown arguments during execution. By default, this raises an ArgumentError.


[View source]
def on_unknown_options(options : Array(String)) #

A hook method for when the command receives unknown options during execution. By default, this raises an ArgumentError.


[View source]
def options : Hash(String, Option) #

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.


[View source]
def parent : Command | Nil #

The parent of the command of which the current command inherits from.


[View source]
def parent=(parent : Command | Nil) #

The parent of the command of which the current command inherits from.


[View source]
def post_run(arguments : Arguments, options : Options) : Nil #

A hook method to run once the #pre_run and main #run methods have been executed.


[View source]
def pre_run(arguments : Arguments, options : Options) : Bool | Nil #

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).


[View source]
abstract def run(arguments : Arguments, options : Options) : Nil #

The main point of execution for the command, where arguments and options can be accessed.


[View source]
abstract def setup : Nil #

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.


[View source]
def stderr : IO #

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.


[View source]
def stderr=(stderr : IO) #

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.


[View source]
def stdin : IO #

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.


[View source]
def stdin=(stdin : IO) #

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.


[View source]
def stdout : IO #

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.


[View source]
def stdout=(stdout : IO) #

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.


[View source]
def summary : String | Nil #

The summary of the command to show in generated help templates.


[View source]
def summary=(summary : String | Nil) #

The summary of the command to show in generated help templates.


[View source]
def usage : Array(String) #

An array of usage strings to display in generated help templates.


[View source]