class

Argy::Command

Inherits Reference < Object

A Command represents a single verb in the CLI hierarchy.

Example:

root = Argy::Command.new( use: "mytool", short: "A fictional dev tool", long: "mytool is a fictional dev tool used to illustrate argy." )

serve = Argy::Command.new( use: "serve [flags]", short: "Start the HTTP server" ) serve.on_run do |cmd, _args| port = cmd.int_flag("port") puts "Serving on port #{port}" end serve.flags.int("port", 'p', 8080, "port to listen on")

root.add_command(serve) root.execute

Constructors

new(use : String, short : String = "", long : String = "", aliases : Array(String) = [] of String, hidden : Bool = false)
Source

Instance methods

add_command(*cmds : Command) : Nil
Source
aliases

Alternative names that route to this command

Source
bool_flag(name : String) : Bool
Source
execute(argv : Array(String) = ARGV.to_a) : Nil

Call this on the root command to parse ARGV and dispatch. If the first token equals this command's own name (e.g. the user passed the program name explicitly), it is stripped before routing so that myapp myapp subcommand and myapp subcommand behave identically.

Source
flags

Local flags — only available to this command

Source
float_flag(name : String) : Float64
Source
hidden

When true, this command is excluded from help listings but still callable

Source
hidden=(hidden : Bool)

When true, this command is excluded from help listings but still callable

Source
int_flag(name : String) : Int32
Source
long

Long description shown at the top of this command's help page

Source
long=(long : String)

Long description shown at the top of this command's help page

Source
name

The first word of use — the canonical command name used for routing

Source
on_persistent_pre_run

Register a callback run from root to current command on every path.

Source
on_pre_run

Register a callback run before this command's body.

Source
on_run

Register the command body callback.

Source
persistent_flags

Persistent flags — inherited by all subcommands

Source
short

One-line description shown in parent's help listing

Source
short=(short : String)

One-line description shown in parent's help listing

Source
stderr

The stream this command writes errors to (own override, else inherited, else the process STDERR).

Source
stderr=(io : IO) : IO

Override this command's (and, by inheritance, its descendants') stderr.

Source
stdout

The stream this command prints to (own override, else inherited, else the process STDOUT).

Source
stdout=(io : IO) : IO

Override this command's (and, by inheritance, its descendants') stdout.

Source
string_flag(name : String) : String
Source
subcommands
Source
use

The usage line – first word is treated as the command name. e.g. "serve [flags]" or just "serve"

Source