These lines of the command definition specify the name of the command (or the
commandline tool, if the command is the root command), the usage, a list of
aliases that can be used to call this command, a one-line summary and a (long)
description. The usage should not include a “usage:” prefix nor the name of
the supercommand, because the latter will be automatically prepended.

Aliases don’t make sense for root commands, but for subcommands they do.

All these methods take the short option form as their first argument, and a
long option form as their second argument. Either the short or the long form
can be nil, but not both (because that would not make any sense). In the
example above, the --more option has no short form.

Each of the above methods also take a block, which will be executed when the
option is found. The argument to the block are the option value (true in
case the option does not have an argument) and the command.

Multivalued options

Each of these four methods take a :multiple option. When set to true, multiple
option valus are accepted, and the option values will be stored in an array.

For example, to parse the command line options string -o foo.txt -o bar.txt
into an array, so that options[:output] contains [ 'foo.txt', 'bar.txt' ],
you can use an option definition like this:

This can also be used for flags (options without arguments). In this case, the
length of the options array is relevant.

For example, you can allow setting the verbosity level using -v -v -v. The
value of options[:verbose].size would then be the verbosity level (three in
this example). The option definition would then look like this:

The run block

run do |opts, args, cmd|
stuff = opts.fetch(:stuff, 'generic stuff')
puts "Doing #{stuff}!"
if opts[:more]
puts 'Doing it even more!'
end
end

The Cri::CommandDSL#run method takes a block with the actual code to
execute. This block takes three arguments: the options, any arguments passed
to the command, and the command itself.

Instead of defining a run block, it is possible to declare a class, the
command runner class (Cri::CommandRunner) that will perform the actual
execution of the command. This makes it easier to break up large run blocks
into manageable pieces.

Subcommands

Commands can have subcommands. For example, the git commandline tool would be
represented by a command that has subcommands named commit, add, and so on.
Commands with subcommands do not use a run block; execution will always be
dispatched to a subcommand (or none, if no subcommand is found).

To add a command as a subcommand to another command, use the
Cri::Command#add_command method, like this: