class

Opal::CLI::Command

Inherits Reference < Object

Represents a command or subcommand node in the CLI hierarchy.

Constructors

new(name : String, description : String = "")
Source

Instance methods

after

Adds a hook after execution

Source
alias_name(*names : String) : self

Adds alias names for this command

Source
aliases
Source
aliases=(aliases : Array(String))
Source
all_options

Collects all available options including inherited global options

Source
allow_unknown_options(allow : Bool = true) : self

Allows unrecognized options or flags to pass through without parsing errors

Source
allow_unknown_options=(allow_unknown_options : Bool)
Source
allow_unknown_options?
Source
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

Source
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

Source
arguments
Source
arguments=(arguments : Array(Argument))
Source
before

Adds a hook before execution

Source
category(cat : String) : self

Sets command category for grouped help rendering

Source
category
Source
category=(category : String | Nil)
Source
command(name : String | Symbol, description : String = "") : Command

Defines a subcommand without a block

Source
command(name : String | Symbol, description : String = "", &block : Command -> Nil) : Command

Defines a subcommand with a configuration block

Source
commands

Alias for subcommands

Source
description(desc : String) : self
Source
description
Source
description=(description : String)
Source
epilog(text : String) : self
Source
example(ex : String) : self

Adds a usage example

Source
examples
Source
examples=(examples : Array(String))
Source
execute(context : Context) : Int32

Executes this command with the provided context

Source
find_command(name : String) : Command | Nil

Finds a subcommand by name or alias

Source
flag(name : Symbol, long : String, short : String | Nil = nil, description : String = "", default : Bool = false, global : Bool = false) : self

Defines a boolean flag (e.g. -q, --quiet or unified "-q, --quiet")

Source
group(name : String, &block : -> Nil) : self

Groups enclosed option/flag definitions into a named category

Source
header(text : String) : self

Sets header/banner text

Source
header_text
Source
header_text=(header_text : String | Nil)
Source
help_handler
Source
help_handler=(help_handler : Context | Nil -> String | Nil | Nil)
Source
help_text(app_name : String, context : Context | Nil = nil) : String

Formats help screen for this command

Source
name
Source
name=(name : String)
Source
on_help

Registers a custom help handler for this command

Source
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"

Source
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. -e src/main.cr, --entry=src/main.cr or unified "-e, --entry=DIR")

Source
options
Source
options=(options : Array(Option))
Source
parent
Source
parent=(parent : Command | Nil)
Source
run

Defines the execution body for this command

Source
section(title : String, &block : HelpSection -> Nil) : self

Adds a custom help section (e.g. PIPELINE COMPOSITION)

Source
sections
Source
sections=(sections : Array(HelpSection))
Source
subcommand(name : String | Symbol, description : String = "") : Command

Alias for command

Source
subcommand(name : String | Symbol, description : String = "", &block : Command -> Nil) : Command
Source
subcommands
Source
subcommands=(subcommands : Hash(String, Command))
Source
summary(text : String) : self

Sets short summary for parent command listings

Source
summary
Source
summary=(summary : String | Nil)
Source
title(text : String) : self

Sets display title

Source
title
Source
title=(title : String | Nil)
Source