Parent

Methods

Class Index [+]

Quicksearch

Gem::Commands::HelpCommand

Public Class Methods

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

Public Instance Methods

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.