#
action
Required
Defines the action name, shortcut and the block that will be executed.
The action block will receive a single args hash containing all the parsed
arguments and flags.
title 'Developer Tools'
usage 'backup [--force --full]'
action 'backup' do |args|
p args
end
$ run backup --force
{"backup"=>true, "--force"=>true, "--full"=>false, "--help"=>false}
Providing a second argument to the action directive, denotes a shortcut.
Note that you also need to define this shortcut in the usage directive
(unless the action does not require any arguments, in which case usage is
optional).
title 'Developer Tools'
usage '(backup | b) [--force --full]'
action 'backup', 'b' do |args|
p args
end
$ run
Usage:
run (backup | b) [--force --full]
run (--help | -h)
$ run b
{"backup"=>false, "b"=>true, "--force"=>false, "--full"=>false, "--help"=>false}
A runfile may contain on action without a name. This will be the default action
that is executed when running run without arguments (instead of showing
usage).
The action name and shortcut may either be strings or symbols. Whichever you choose is a matter of personal preference.