class WhiteCloth::CLI::Commands::Help
@author Denis Defreyne @author David Love
The help
command show the user a brief summary of the available sub-commands, and the short description of each of those commands.
Further help is available to the user, if one of the sub-commands is named as an argument to this command. In that case, the longer help for the command is displayed.
@note This class is merely a helper class: the actual text, options
and other details are drawn directly from the source code of those commands. In the execution of this command, we rely on the +cri+ and +cli+ libraries to do the hard work of actually processing the sub-commands.
Public Instance Methods
aliases()
click to toggle source
The aliases this sub-command is known by
# File lib/whitecloth/cli/commands/help.rb, line 41 def aliases [] end
long_desc()
click to toggle source
A longer description, detailing both the purpose and the use of this command
# File lib/whitecloth/cli/commands/help.rb, line 52 def long_desc 'Show help for the given command, or show general help. When no ' + 'command is given, a list of available commands is displayed, as ' + 'well as a list of global command-line options. When a command is ' + 'given, a command description as well as command-specific ' + 'command-line options are shown.' end
name()
click to toggle source
The name of the sub-command (as it appears in the command line app)
# File lib/whitecloth/cli/commands/help.rb, line 36 def name 'help' end
run(options, arguments)
click to toggle source
Execute the command
# File lib/whitecloth/cli/commands/help.rb, line 66 def run(options, arguments) # Check arguments if arguments.size > 1 $stderr.puts "usage: #{usage}" exit 1 end if arguments.length == 0 # Build help text text = '' # Add title text << "A command-line tool for managing WhiteCloth realms.\n" # Add available commands text << "\n" text << "Available commands:\n" text << "\n" @base.commands.sort.each do |command| text << sprintf(" %-20s %s\n", command.name, command.short_desc) end # Add global options text << "\n" text << "Global options:\n" text << "\n" @base.global_option_definitions.sort { |x,y| x[:long] <=> y[:long] }.each do |opt_def| text << sprintf(" -%1s --%-15s %s\n", opt_def[:short], opt_def[:long], opt_def[:desc]) end # Display text puts text elsif arguments.length == 1 command = @base.command_named(arguments[0]) puts command.help end end
short_desc()
click to toggle source
A short help text describing the purpose of this command
# File lib/whitecloth/cli/commands/help.rb, line 46 def short_desc 'Show help for a command' end
usage()
click to toggle source
Show
the user the basic syntax of this command
# File lib/whitecloth/cli/commands/help.rb, line 61 def usage "whitecloth help [command]" end