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
-
#arg(name : Symbol, description : String = "", required : Bool = false, default : String | Nil = nil, type : Symbol = :string, multiple : Bool = false, choices : Array(String) | Nil = nil, value_name : String | Nil = nil) : self
Ergonomic shorthand for argument
-
#argument(name : Symbol, description : String = "", required : Bool = false, default : String | Nil = nil, type : Symbol = :string, multiple : Bool = false, choices : Array(String) | Nil = nil, value_name : String | Nil = nil) : self
Defines a positional argument
- #arguments : Array(Argument)
- #arguments=(arguments : Array(Argument))
- #banner(text : String) : self
-
#before(&block : Context -> Nil) : self
Adds a hook before execution
-
#category(cat : String) : self
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
-
#commands : Hash(String, Command)
Alias for subcommands
- #description(desc : String) : self
- #description : String
- #description=(description : String)
- #epilog(text : String) : self
-
#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.
-
#footer(text : String) : self
Sets footer/epilog text
- #footer_text : String | Nil
- #footer_text=(footer_text : String | Nil)
-
#group(name : String, &block : -> Nil) : self
Groups enclosed option/flag definitions into a named category
-
#header(text : String) : self
Sets header/banner text
- #header_text : String | Nil
- #header_text=(header_text : String | Nil)
- #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
-
#opt(name : Symbol, spec : String, description : String = "", type : Symbol | Nil = nil, default : OptionValue = nil, required : Bool = false, global : Bool = false, choices : Array(String) | Nil = nil, env_var : String | Nil = nil, group : String | Nil = nil) : self
Shorthand for option with unified spec string like "-d, --delimiter=CHAR"
-
#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
-
#section(title : String, &block : HelpSection -> Nil) : self
Adds a custom help section (e.g.
- #sections : Array(HelpSection)
- #sections=(sections : Array(HelpSection))
-
#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))
-
#summary(text : String) : self
Sets short summary for parent command listings
- #summary : String | Nil
- #summary=(summary : String | Nil)
-
#title(text : String) : self
Sets display title
- #title : String | Nil
- #title=(title : String | Nil)
Constructor Detail
Instance Method Detail
Collects all available options including inherited global options
Allows unrecognized options or flags to pass through without parsing errors
Ergonomic shorthand for argument
Defines a positional argument
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 or unified "-q, --quiet")
Groups enclosed option/flag definitions into a named category
Formats help screen for this command
Registers a custom help handler for this command
Shorthand for option with unified spec string like "-d, --delimiter=CHAR"
Defines a valued option (e.g. -e src/main.cr, --entry=src/main.cr or unified "-e, --entry=DIR")
Defines the execution body for this command
Adds a custom help section (e.g. PIPELINE COMPOSITION)
Alias for command