Parent

Methods

Class Index [+]

Quicksearch

Gem::Commands::HelpCommand

Public Class Methods

new() click to toggle source
    # File lib/rubygems/commands/help_command.rb, line 86
86:   def initialize
87:     super 'help', "Provide help on the 'gem' command"
88:   end

Public Instance Methods

execute() click to toggle source
     # File lib/rubygems/commands/help_command.rb, line 103
103:   def execute
104:     command_manager = Gem::CommandManager.instance
105:     arg = options[:args][0]
106: 
107:     if begins? "commands", arg then
108:       out = []
109:       out << "GEM commands are:"
110:       out << nil
111: 
112:       margin_width = 4
113: 
114:       desc_width = command_manager.command_names.map { |n| n.size }.max + 4
115: 
116:       summary_width = 80 - margin_width - desc_width
117:       wrap_indent = ' ' * (margin_width + desc_width)
118:       format = "#{' ' * margin_width}%-#{desc_width}s%s"
119: 
120:       command_manager.command_names.each do |cmd_name|
121:         summary = command_manager[cmd_name].summary
122:         summary = wrap(summary, summary_width).split "\n"
123:         out << sprintf(format, cmd_name, summary.shift)
124:         until summary.empty? do
125:           out << "#{wrap_indent}#{summary.shift}"
126:         end
127:       end
128: 
129:       out << nil
130:       out << "For help on a particular command, use 'gem help COMMAND'."
131:       out << nil
132:       out << "Commands may be abbreviated, so long as they are unambiguous."
133:       out << "e.g. 'gem i rake' is short for 'gem install rake'."
134: 
135:       say out.join("\n")
136: 
137:     elsif begins? "options", arg then
138:       say Gem::Command::HELP
139: 
140:     elsif begins? "examples", arg then
141:       say EXAMPLES
142: 
143:     elsif begins? "platforms", arg then
144:       say PLATFORMS
145: 
146:     elsif options[:help] then
147:       command = command_manager[options[:help]]
148:       if command
149:         # help with provided command
150:         command.invoke("--help")
151:       else
152:         alert_error "Unknown command #{options[:help]}.  Try 'gem help commands'"
153:       end
154: 
155:     elsif arg then
156:       possibilities = command_manager.find_command_possibilities(arg.downcase)
157:       if possibilities.size == 1
158:         command = command_manager[possibilities.first]
159:         command.invoke("--help")
160:       elsif possibilities.size > 1
161:         alert_warning "Ambiguous command #{arg} (#{possibilities.join(', ')})"
162:       else
163:         alert_warning "Unknown command #{arg}. Try gem help commands"
164:       end
165: 
166:     else
167:       say Gem::Command::HELP
168:     end
169:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.