Class: Acclaim::Command
- Inherits:
-
Object
- Object
- Acclaim::Command
- Defined in:
- lib/acclaim/command.rb,
lib/acclaim/command/dsl.rb,
lib/acclaim/command/help.rb,
lib/acclaim/command/parser.rb,
lib/acclaim/command/version.rb,
lib/acclaim/command/dsl/root.rb,
lib/acclaim/command/help/template.rb
Overview
A command is a single word whose meaning the program understands. It calls upon a function of the program, which may be fine-tuned with options and given arguments.
app --global-option do --option
A subcommand benefits from its parent’s option processing.
app --global-option do something --option-for-do --option-for-something
A command can be created in the following form:
class App::Command < Acclaim::Command
option :verbose, '-v', '--verbose', 'Run verbosely'
end
A subcommand can be created by inheriting from another command:
class App::Command::Do < App::Command
opt :what, '-W', '--what', 'What to do', arity: [1, 0], required: true
when_called do |options, arguments|
puts "Verbose? #{options.verbose? ? :yes : :no}"
puts "Doing #{options.what} with #{arguments.join ' and ')}!"
end
end
Then, in your application’s binary, you may simply write:
App::Command.run *ARGV
See it in action:
$ app --verbose do --what testing acclaim safeguard
Verbose? yes
Doing testing with acclaim and safeguard!
Defined Under Namespace
Modules: DSL, Help, Version Classes: Parser
Class Method Summary collapse
-
.inherited(command) ⇒ Object
Add the class methods to the subclass and add it to this command’s list of subcommands.