Class: Gem::HelpCommand
- Includes:
- CommandAids
- Defined in:
- lib/rubygems/gem_commands.rb
Instance Attribute Summary
Attributes inherited from Command
#command, #defaults, #options, #program_name, #summary
Instance Method Summary collapse
- #arguments ⇒ Object
- #execute ⇒ Object
-
#initialize ⇒ HelpCommand
constructor
A new instance of HelpCommand.
- #usage ⇒ Object
Methods included from CommandAids
#begins?, #get_all_gem_names, #get_one_gem_name, #get_one_optional_argument
Methods inherited from Command
add_common_option, #add_option, add_specific_extra_args, common_options, #defaults_str, extra_args, extra_args=, #handles?, #invoke, #merge_options, #remove_option, #show_help, specific_extra_args, specific_extra_args_hash, #when_invoked
Methods included from DefaultUserInteraction
#ui, ui, #ui=, ui=, #use_ui, use_ui
Constructor Details
#initialize ⇒ HelpCommand
Returns a new instance of HelpCommand.
1457 1458 1459 |
# File 'lib/rubygems/gem_commands.rb', line 1457 def initialize super('help', "Provide help on the 'gem' command") end |
Instance Method Details
#arguments ⇒ Object
1465 1466 1467 1468 1469 1470 1471 1472 |
# File 'lib/rubygems/gem_commands.rb', line 1465 def arguments args = <<-EOF commands List all 'gem' commands examples Show examples of 'gem' usage <command> Show specific help for <command> EOF return args.gsub(/^\s+/, '') end |
#execute ⇒ Object
1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 |
# File 'lib/rubygems/gem_commands.rb', line 1474 def execute arg = [:args][0] if begins?("commands", arg) out = [] out << "GEM commands are:" out << nil margin_width = 4 desc_width = command_manager.command_names.collect {|n| n.size}.max + 4 summary_width = 80 - margin_width - desc_width wrap_indent = ' ' * (margin_width + desc_width) format = "#{' ' * margin_width}%-#{desc_width}s%s" command_manager.command_names.each do |cmd_name| summary = command_manager[cmd_name].summary summary = wrap(summary, summary_width).split "\n" out << sprintf(format, cmd_name, summary.shift) until summary.empty? do out << "#{wrap_indent}#{summary.shift}" end end out << nil out << "For help on a particular command, use 'gem help COMMAND'." out << nil out << "Commands may be abbreviated, so long as they are unambiguous." out << "e.g. 'gem i rake' is short for 'gem install rake'." say out.join("\n") elsif begins?("options", arg) say Gem::HELP elsif begins?("examples", arg) say Gem::EXAMPLES elsif [:help] command = command_manager[[:help]] if command # help with provided command command.invoke("--help") else alert_error "Unknown command #{[:help]}. Try 'gem help commands'" end elsif arg possibilities = command_manager.find_command_possibilities(arg.downcase) if possibilities.size == 1 command = command_manager[possibilities.first] command.invoke("--help") elsif possibilities.size > 1 alert_warning "Ambiguous command #{arg} (#{possibilities.join(', ')})" else alert_warning "Unknown command #{arg}. Try gem help commands" end else say Gem::HELP end end |
#usage ⇒ Object
1461 1462 1463 |
# File 'lib/rubygems/gem_commands.rb', line 1461 def usage "#{program_name} ARGUMENT" end |