Module: Acclaim::Command::Help
- Defined in:
- lib/acclaim/command/help.rb,
lib/acclaim/command/help/template.rb
Overview
Module which adds help support to a command.
Defined Under Namespace
Modules: Template
Class Method Summary collapse
-
.create(*args) ⇒ Object
Creates a help subcommand that inherits from the given
base
command and stores the class in theHelp
constant ofbase
. -
.display_for(*args) ⇒ Object
Displays a very simple help screen for the given command and all its subcommands.
Class Method Details
.create(*args) ⇒ Object
Creates a help subcommand that inherits from the given base
command and stores the class in the Help
constant of base
. When called, the command displays a help screen including information for all commands and then exits.
The last argument can be a configuration hash, which accepts the following options:
- :options
-
If
true
, will add a help option to thebase
command. - :switches
-
The switches used when creating the help option.
- :include_root
-
Includes the root command when displaying a command’s usage.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/acclaim/command/help.rb', line 26 def create(*args) opts, base = args.extract_ribbon!, args.shift base, opts if opts. true base.const_set(:Help, Class.new(base)).tap do |help_command| help_command.when_called do |, args| # TODO: implement a way to specify a command to the help option # and command. # display_for options.command || args.pop display_for base.root, opts end end end |
.display_for(*args) ⇒ Object
Displays a very simple help screen for the given command and all its subcommands.
The last argument can be a configuration hash, which accepts the following options:
- :include_root
-
Includes the root command when displaying a command’s usage.
47 48 49 50 51 |
# File 'lib/acclaim/command/help.rb', line 47 def display_for(*args) , command = args.extract_ribbon!, args.shift puts Help::Template.for(command, ) if command..any? command.subcommands.each { |subcommand| display_for(subcommand, ) } end |