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.

Since:

  • 0.0.1

Defined Under Namespace

Modules: Template

Class Method Summary collapse

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 the base command.

:switches

The switches used when creating the help option.

:include_root

Includes the root command when displaying a command’s usage.

Since:

  • 0.0.1



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
  add_options_to! base, opts if opts.options? true
  base.const_set(:Help, Class.new(base)).tap do |help_command|
    help_command.when_called do |options, 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.

Since:

  • 0.0.1



47
48
49
50
51
# File 'lib/acclaim/command/help.rb', line 47

def display_for(*args)
  options, command = args.extract_ribbon!, args.shift
  puts Help::Template.for(command, options) if command.options.any?
  command.subcommands.each { |subcommand| display_for(subcommand, options) }
end