Class: SANStore::CLI::Commands::Help
- Inherits:
-
Cri::Command
- Object
- Cri::Command
- SANStore::CLI::Commands::Help
- Defined in:
- lib/SANStore/cli/commands/help.rb
Overview
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.
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.
Instance Attribute Summary
Attributes inherited from Cri::Command
Instance Method Summary collapse
-
#aliases ⇒ Object
The aliases this sub-command is known by.
-
#long_desc ⇒ Object
A longer description, detailing both the purpose and the use of this command.
-
#name ⇒ Object
The name of the sub-command (as it appears in the command line app).
-
#run(options, arguments) ⇒ Object
Execute the command.
-
#short_desc ⇒ Object
A short help text describing the purpose of this command.
-
#usage ⇒ Object
Show the user the basic syntax of this command.
Methods inherited from Cri::Command
#<=>, #help, #option_definitions
Instance Method Details
#aliases ⇒ Object
The aliases this sub-command is known by
41 42 43 |
# File 'lib/SANStore/cli/commands/help.rb', line 41 def aliases [] end |
#long_desc ⇒ Object
A longer description, detailing both the purpose and the use of this command
52 53 54 55 56 57 58 |
# File 'lib/SANStore/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 ⇒ Object
The name of the sub-command (as it appears in the command line app)
36 37 38 |
# File 'lib/SANStore/cli/commands/help.rb', line 36 def name 'help' end |
#run(options, arguments) ⇒ Object
Execute the command
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/SANStore/cli/commands/help.rb', line 66 def run(, 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 iSCSI targets on OpenSolaris.\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 ⇒ Object
A short help text describing the purpose of this command
46 47 48 |
# File 'lib/SANStore/cli/commands/help.rb', line 46 def short_desc 'Show help for a command' end |
#usage ⇒ Object
Show the user the basic syntax of this command
61 62 63 |
# File 'lib/SANStore/cli/commands/help.rb', line 61 def usage "store help [command]" end |