Class: Amp::Help::CommandHelpEntry

Inherits:
HelpEntry show all
Defined in:
lib/amp-front/help/help.rb

Overview

Represents a command’s help entry. All commands have one of these, and in fact, when the command is created, it creates a help entry to go with it.

Commands are actually quite complicated, and themselves know how to educate users about their use, so we have surprisingly little logic in this class.

Instance Method Summary collapse

Methods inherited from HelpEntry

from_file

Constructor Details

#initialize(name, command) ⇒ CommandHelpEntry

Creates a new command help entry. Differing arguments, because instead of text, we need the command itself. One might think: why not just pass in the command’s help information instead? If you have a command object, you have command.help, no? Well, the reason is two-fold: the help information might be updated later, and there is more to printing a command’s help entry than just the command.help() method.

Parameters:

  • name (String)

    the name of the command

  • command (Amp::Command)

    the command being represented.



230
231
232
233
# File 'lib/amp-front/help/help.rb', line 230

def initialize(name, command)
  super(name)
  @command = command
end

Instance Method Details

#descObject

Describes the entry briefly, so if the user must pick, they have a decent shot at knowing what this entry is about. Hopefully.

In the case of a command, grab the command’s “desc” information.

Returns:

  • a description of the entry based on its content



259
260
261
# File 'lib/amp-front/help/help.rb', line 259

def desc
  %Q{a command help entry ("#{@command.desc}")}
end

#text(options = {}) ⇒ String

Returns the help text to display for this entry.

For a command-based entry, simply run its educate method, since commands know how to present their help information.

Parameters:

  • options (Hash) (defaults to: {})

    the options for the process - that way the help commands can access the user’s run-time options and global configuration. For example, if the user passes in –verbose or –quiet, each help entry could handle that differently. Who are we to judge?

Returns:

  • (String)

    the help text for the entry.



246
247
248
249
250
# File 'lib/amp-front/help/help.rb', line 246

def text(options = {})
  instantiated = @command.new
  instantiated.collect_options([])
  "#{@command.desc}\n#{instantiated.education}"
end