class
Opal::CLI::Command
- Opal::CLI::Command
- Reference
- Object
Overview
Represents a command or subcommand node in the CLI hierarchy.
Direct Known Subclasses
Defined in:
opal/cli/command.crConstructors
Instance Method Summary
-
#after(&block : Context -> Nil) : self
Adds a hook after execution
-
#alias_name(*names : String) : self
Adds alias names for this command
- #aliases : Array(String)
- #aliases=(aliases : Array(String))
-
#all_options : Array(Option)
Collects all available options including inherited global options
-
#allow_unknown_options(allow : Bool = true) : self
Allows unrecognized options or flags to pass through without parsing errors
- #allow_unknown_options=(allow_unknown_options : Bool)
- #allow_unknown_options? : Bool
-
#argument(name : Symbol, description : String = "", required : Bool = false, default : String | Nil = nil, type : Symbol = :string) : self
Defines a positional argument
- #arguments : Array(Argument)
- #arguments=(arguments : Array(Argument))
-
#before(&block : Context -> Nil) : self
Adds a hook before execution
-
#category(cat : String) : self
Sets command description Sets command category for grouped help rendering
- #category : String | Nil
- #category=(category : String | Nil)
-
#command(name : String | Symbol, description : String = "") : Command
Defines a subcommand without a block
-
#command(name : String | Symbol, description : String = "", &block : Command -> Nil) : Command
Defines a subcommand with a configuration block
- #description(desc : String) : self
- #description : String
- #description=(description : String)
-
#example(ex : String) : self
Adds a usage example
- #examples : Array(String)
- #examples=(examples : Array(String))
-
#execute(context : Context) : Int32
Executes this command with the provided context
-
#find_command(name : String) : Command | Nil
Finds a subcommand by name or alias
-
#flag(name : Symbol, long : String, short : String | Nil = nil, description : String = "", default : Bool = false, global : Bool = false) : self
Defines a boolean flag (e.g.
- #help_handler : Context | Nil -> String | Nil | Nil
- #help_handler=(help_handler : Context | Nil -> String | Nil | Nil)
-
#help_text(app_name : String, context : Context | Nil = nil) : String
Formats help screen for this command
- #name : String
- #name=(name : String)
-
#on_help(&block : Context | Nil -> String | Nil) : self
Registers a custom help handler for this command
-
#option(name : Symbol, long : String, short : String | Nil = nil, description : String = "", type : Symbol = :string, default : OptionValue = nil, required : Bool = false, global : Bool = false, choices : Array(String) | Nil = nil, env_var : String | Nil = nil) : self
Defines a valued option (e.g.
- #options : Array(Option)
- #options=(options : Array(Option))
- #parent : Command | Nil
- #parent=(parent : Command | Nil)
-
#run(&block : Context -> Nil | Int32) : self
Defines the execution body for this command
-
#subcommand(name : String | Symbol, description : String = "") : Command
Alias for command
- #subcommand(name : String | Symbol, description : String = "", &block : Command -> Nil) : Command
- #subcommands : Hash(String, Command)
- #subcommands=(subcommands : Hash(String, Command))
Constructor Detail
Instance Method Detail
Collects all available options including inherited global options
Allows unrecognized options or flags to pass through without parsing errors
Defines a positional argument
Sets command description Sets command category for grouped help rendering
Defines a subcommand without a block
Defines a subcommand with a configuration block
Executes this command with the provided context
Defines a boolean flag (e.g. -q, --quiet)
Formats help screen for this command
Registers a custom help handler for this command
Defines a valued option (e.g. -e src/main.cr, --entry=src/main.cr)
Defines the execution body for this command
Alias for command