class
Argy::Command
- Argy::Command
- Reference
- Object
Overview
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
Defined in:
argy/command.crConstructors
Instance Method Summary
- #add_command(*cmds : Command) : Nil
- #bool_flag(name : String) : Bool
-
#execute(argv : Array(String) = ARGV.to_a) : Nil
Call this on the root command to parse ARGV and dispatch.
-
#flags : FlagSet
Local flags — only available to this command
- #float_flag(name : String) : Float64
- #int_flag(name : String) : Int32
-
#long : String
Long description shown at the top of this command's help page
-
#long=(long : String)
Long description shown at the top of this command's help page
-
#name : String
The first word of use — the canonical command name used for routing
-
#on_persistent_pre_run(&block : Command, Array(String) -> ) : self
Register a callback run from root to current command on every path.
-
#on_pre_run(&block : Command, Array(String) -> ) : self
Register a callback run before this command's body.
-
#on_run(&block : Command, Array(String) -> ) : self
Register the command body callback.
-
#persistent_flags : FlagSet
Persistent flags — inherited by all subcommands
- #print_help(io : IO = STDOUT) : Nil
-
#short : String
One-line description shown in parent's help listing
-
#short=(short : String)
One-line description shown in parent's help listing
- #string_flag(name : String) : String
- #subcommands : Hash(String, Command)
-
#use : String
The usage line – first word is treated as the command name.
Constructor Detail
Instance Method Detail
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.
Register a callback run from root to current command on every path.
Register a callback run before this command's body.
Register the command body callback.
The usage line – first word is treated as the command name. e.g. "serve [flags]" or just "serve"