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 83
83:   def initialize
84:     super 'help', "Provide help on the 'gem' command"
85:   end

Public Instance methods

[Source]

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

[Validate]