Class: Amp::Help::CommandHelpEntry
- 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
-
#desc ⇒ Object
Describes the entry briefly, so if the user must pick, they have a decent shot at knowing what this entry is about.
-
#initialize(name, command) ⇒ CommandHelpEntry
constructor
Creates a new command help entry.
-
#text(options = {}) ⇒ String
Returns the help text to display for this entry.
Methods inherited from HelpEntry
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.
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
#desc ⇒ Object
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.
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.
246 247 248 249 250 |
# File 'lib/amp-front/help/help.rb', line 246 def text( = {}) instantiated = @command.new instantiated.([]) "#{@command.desc}\n#{instantiated.education}" end |