Class: Q::Help

Inherits:
Command show all
Defined in:
lib/q/commands/help.rb

Instance Attribute Summary

Attributes inherited from Command

#registered_shortcuts

Instance Method Summary collapse

Methods inherited from Command

#usage

Constructor Details

#initializeHelp

Returns a new instance of Help.



3
4
5
# File 'lib/q/commands/help.rb', line 3

def initialize
	super("COMMAND -- print help for COMMAND")
end

Instance Method Details

#execute(shortcut, terms) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/q/commands/help.rb', line 7

def execute(shortcut, terms)
	shortcut = terms.shift.to_sym unless terms.empty?
	if command = Q.commands[shortcut]
		command.help(shortcut, terms)
	else
		shortcut.to_s + ": unknown command"
	end
end

#help(shortcut, terms) ⇒ Object



16
17
18
19
20
21
# File 'lib/q/commands/help.rb', line 16

def help(shortcut, terms)
	([	%q{Usage: q [SHORTCUT] [TERM] ...},
		%q{Perform the command specified by SHORTCUT for the specified TERMs.},
		""
	] + Q.unique_commands.map{ |command| "  " + command.usage }.sort).join($/)
end