Class: LibGems::Commands::HelpCommand
- Inherits:
-
LibGems::Command
- Object
- LibGems::Command
- LibGems::Commands::HelpCommand
- Defined in:
- lib/libgems/commands/help_command.rb
Constant Summary collapse
- EXAMPLES =
:stopdoc:
<<-EOF Some examples of 'gem' usage. * Install 'rake', either from local directory or remote server: gem install rake * Install 'rake', only from remote server: gem install rake --remote * Install 'rake' from remote server, and run unit tests, and generate RDocs: gem install --remote rake --test --rdoc --ri * Install 'rake', but only version 0.3.1, even if dependencies are not met, and into a user-specific directory: gem install rake --version 0.3.1 --force --user-install * List local gems whose name begins with 'D': gem list D * List local and remote gems whose name contains 'log': gem search log --both * List only remote gems whose name contains 'log': gem search log --remote * Uninstall 'rake': gem uninstall rake * Create a gem: See http://rubygems.rubyforge.org/wiki/wiki.pl?CreateAGemInTenMinutes * See information about #{LibGems::NAME}: gem environment * Update all gems on your system: gem update EOF
- PLATFORMS =
<<-'EOF' #{LibGems::NAME} platforms are composed of three parts, a CPU, an OS, and a version. These values are taken from values in rbconfig.rb. You can view your current platform by running `gem environment`. #{LibGems::NAME} matches platforms as follows: * The CPU must match exactly, unless one of the platforms has "universal" as the CPU. * The OS must match exactly. * The versions must match exactly unless one of the versions is nil. For commands that install, uninstall and list gems, you can override what #{LibGems::NAME} thinks your platform is with the --platform option. The platform you pass must match "#{cpu}-#{os}" or "#{cpu}-#{os}-#{version}". On mswin platforms, the version is the compiler version, not the OS version. (Ruby compiled with VC6 uses "60" as the compiler version, VC8 uses "80".) Example platforms: x86-freebsd # Any FreeBSD version on an x86 CPU universal-darwin-8 # Darwin 8 only gems that run on any CPU x86-mswin32-80 # Windows gems compiled with VC8 When building platform gems, set the platform in the gem specification to LibGems::Platform::CURRENT. This will correctly mark the gem with your ruby's platform. EOF
Instance Attribute Summary
Attributes inherited from LibGems::Command
#command, #defaults, #options, #program_name, #summary
Instance Method Summary collapse
-
#arguments ⇒ Object
:nodoc:.
- #execute ⇒ Object
-
#initialize ⇒ HelpCommand
constructor
:startdoc:.
-
#usage ⇒ Object
:nodoc:.
Methods inherited from LibGems::Command
add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, common_options, #defaults_str, #description, extra_args, extra_args=, #get_all_gem_names, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #merge_options, #remove_option, #show_help, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked
Methods included from UserInteraction
Methods included from DefaultUserInteraction
ui, #ui, ui=, #ui=, use_ui, #use_ui
Constructor Details
#initialize ⇒ HelpCommand
:startdoc:
86 87 88 |
# File 'lib/libgems/commands/help_command.rb', line 86 def initialize super 'help', "Provide help on the 'gem' command" end |
Instance Method Details
#arguments ⇒ Object
:nodoc:
90 91 92 93 94 95 96 97 |
# File 'lib/libgems/commands/help_command.rb', line 90 def arguments # :nodoc: 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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/libgems/commands/help_command.rb', line 103 def execute command_manager = LibGems::CommandManager.instance arg = [:args][0] if begins? "commands", arg then out = [] out << "GEM commands are:" out << nil margin_width = 4 desc_width = command_manager.command_names.map { |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 then say LibGems::Command::HELP elsif begins? "examples", arg then say EXAMPLES elsif begins? "platforms", arg then say PLATFORMS elsif [:help] then 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 then 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 LibGems::Command::HELP end end |
#usage ⇒ Object
:nodoc:
99 100 101 |
# File 'lib/libgems/commands/help_command.rb', line 99 def usage # :nodoc: "#{program_name} ARGUMENT" end |