class Opal::CLI::Command

Overview

Represents a command or subcommand node in the CLI hierarchy.

Direct Known Subclasses

Defined in:

opal/cli/command.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(name : String, description : String = "") #

[View source]

Instance Method Detail

def after(&block : Context -> Nil) : self #

Adds a hook after execution


[View source]
def alias_name(*names : String) : self #

Adds alias names for this command


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

[View source]
def aliases=(aliases : Array(String)) #

[View source]
def all_options : Array(Option) #

Collects all available options including inherited global options


[View source]
def allow_unknown_options(allow : Bool = true) : self #

Allows unrecognized options or flags to pass through without parsing errors


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

[View source]
def allow_unknown_options? : Bool #

[View source]
def argument(name : Symbol, description : String = "", required : Bool = false, default : String | Nil = nil, type : Symbol = :string) : self #

Defines a positional argument


[View source]
def arguments : Array(Argument) #

[View source]
def arguments=(arguments : Array(Argument)) #

[View source]
def before(&block : Context -> Nil) : self #

Adds a hook before execution


[View source]
def category(cat : String) : self #

Sets command description Sets command category for grouped help rendering


[View source]
def category : String | Nil #

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

[View source]
def command(name : String | Symbol, description : String = "") : Command #

Defines a subcommand without a block


[View source]
def command(name : String | Symbol, description : String = "", &block : Command -> Nil) : Command #

Defines a subcommand with a configuration block


[View source]
def description(desc : String) : self #

[View source]
def description : String #

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

[View source]
def example(ex : String) : self #

Adds a usage example


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

[View source]
def examples=(examples : Array(String)) #

[View source]
def execute(context : Context) : Int32 #

Executes this command with the provided context


[View source]
def find_command(name : String) : Command | Nil #

Finds a subcommand by name or alias


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


[View source]
def help_handler : Context | Nil -> String | Nil | Nil #

[View source]
def help_handler=(help_handler : Context | Nil -> String | Nil | Nil) #

[View source]
def help_text(app_name : String, context : Context | Nil = nil) : String #

Formats help screen for this command


[View source]
def name : String #

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

[View source]
def on_help(&block : Context | Nil -> String | Nil) : self #

Registers a custom help handler for this command


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


[View source]
def options : Array(Option) #

[View source]
def options=(options : Array(Option)) #

[View source]
def parent : Command | Nil #

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

[View source]
def run(&block : Context -> Nil | Int32) : self #

Defines the execution body for this command


[View source]
def subcommand(name : String | Symbol, description : String = "") : Command #

Alias for command


[View source]
def subcommand(name : String | Symbol, description : String = "", &block : Command -> Nil) : Command #

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

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

[View source]