Class Gem::Commands::HelpCommand
In: lib/rubygems/commands/help_command.rb
Parent: Gem::Command

Methods

execute   new  

Public Class methods

[Source]

    # File lib/rubygems/commands/help_command.rb, line 88
88:   def initialize
89:     super 'help', "Provide help on the 'gem' command"
90:   end

Public Instance methods

[Source]

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

[Validate]