Class: HelpCommand
- Inherits:
-
Object
- Object
- HelpCommand
- Defined in:
- lib/woodstove/helpcommand.rb
Overview
woodstove helpcommand - help command for woodstove Copyright © 2016 the furry entertainment project Licensed under the MIT license.
Instance Method Summary collapse
-
#cmdify(command) ⇒ Object
Produce a formatted command string for the given command.
- #incorrect_usage ⇒ Object
- #info ⇒ Object
-
#initialize(cmd) ⇒ HelpCommand
constructor
A new instance of HelpCommand.
- #long ⇒ Object
- #opts ⇒ Object
- #run(args) ⇒ Object
- #short ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(cmd) ⇒ HelpCommand
6 7 8 |
# File 'lib/woodstove/helpcommand.rb', line 6 def initialize cmd @cmd = cmd end |
Instance Method Details
#cmdify(command) ⇒ Object
Produce a formatted command string for the given command.
16 17 18 19 |
# File 'lib/woodstove/helpcommand.rb', line 16 def cmdify command optprefix = command.opts != '' ? ' ' + command.opts : '' "#{command.long}, #{command.short}#{optprefix}" end |
#incorrect_usage ⇒ Object
40 41 42 43 |
# File 'lib/woodstove/helpcommand.rb', line 40 def incorrect_usage usage puts "For more information: `#{@cmd} help`" end |
#info ⇒ Object
13 |
# File 'lib/woodstove/helpcommand.rb', line 13 def info; 'Prints help information.'; end |
#long ⇒ Object
10 |
# File 'lib/woodstove/helpcommand.rb', line 10 def long; 'help'; end |
#opts ⇒ Object
12 |
# File 'lib/woodstove/helpcommand.rb', line 12 def opts; ''; end |
#run(args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/woodstove/helpcommand.rb', line 20 def run args usage # Get the length of the longest command string, so that we can pad the # information in the output. max_length = 0 $argmanager.commands.each do |command| max_length = [max_length, cmdify(command[1]).length].max end # Print each command's information, with padding after the command string. puts "\nOptions:" $argmanager.commands.each do |command| padded = "%-#{max_length}s" % cmdify(command[1]) puts " #{padded} - #{command[1].info}" end end |
#short ⇒ Object
11 |
# File 'lib/woodstove/helpcommand.rb', line 11 def short; 'h'; end |
#usage ⇒ Object
37 38 39 |
# File 'lib/woodstove/helpcommand.rb', line 37 def usage puts "Usage: #{@cmd} [command] [options]" end |