Class: Gem::Commands::HelpCommand

Inherits:
Gem::Command show all
Defined in:
lib/rubygems/commands/help_command.rb

Constant Summary collapse

EXAMPLES =

:stopdoc:

"Some examples of 'gem' usage.\n\n* Install 'rake', either from local directory or remote server:\n\n  gem install rake\n\n* Install 'rake', only from remote server:\n\n  gem install rake --remote\n\n* Install 'rake', but only version 0.3.1, even if dependencies\nare not met, and into a user-specific directory:\n\n  gem install rake --version 0.3.1 --force --user-install\n\n* List local gems whose name begins with 'D':\n\n  gem list D\n\n* List local and remote gems whose name contains 'log':\n\n  gem search log --both\n\n* List only remote gems whose name contains 'log':\n\n  gem search log --remote\n\n* Uninstall 'rake':\n\n  gem uninstall rake\n\n* Create a gem:\n\n  See http://guides.rubygems.org/make-your-own-gem/\n\n* See information about RubyGems:\n\n  gem environment\n\n* Update all gems on your system:\n\n  gem update\n\n* Update your local version of RubyGems\n\n  gem update --system\n"
PLATFORMS =
"RubyGems platforms are composed of three parts, a CPU, an OS, and a\nversion.  These values are taken from values in rbconfig.rb.  You can view\nyour current platform by running `gem environment`.\n\nRubyGems matches platforms as follows:\n\n* The CPU must match exactly unless one of the platforms has\n  \"universal\" as the CPU or the local CPU starts with \"arm\" and the gem's\n  CPU is exactly \"arm\" (for gems that support generic ARM architecture).\n* The OS must match exactly.\n* The versions must match exactly unless one of the versions is nil.\n\nFor commands that install, uninstall and list gems, you can override what\nRubyGems thinks your platform is with the --platform option.  The platform\nyou pass must match \"\#{cpu}-\#{os}\" or \"\#{cpu}-\#{os}-\#{version}\".  On mswin\nplatforms, the version is the compiler version, not the OS version.  (Ruby\ncompiled with VC6 uses \"60\" as the compiler version, VC8 uses \"80\".)\n\nFor the ARM architecture, gems with a platform of \"arm-linux\" should run on a\nreasonable set of ARM CPUs and not depend on instructions present on a limited\nsubset of the architecture.  For example, the binary should run on platforms\narmv5, armv6hf, armv6l, armv7, etc.  If you use the \"arm-linux\" platform\nplease test your gem on a variety of ARM hardware before release to ensure it\nfunctions correctly.\n\nExample platforms:\n\nx86-freebsd        # Any FreeBSD version on an x86 CPU\nuniversal-darwin-8 # Darwin 8 only gems that run on any CPU\nx86-mswin32-80     # Windows gems compiled with VC8\narmv7-linux        # Gem complied for an ARMv7 CPU running linux\narm-linux          # Gem compiled for any ARM CPU running linux\n\nWhen building platform gems, set the platform in the gem specification to\nGem::Platform::CURRENT.  This will correctly mark the gem with your ruby's\nplatform.\n"

Instance Attribute Summary

Attributes inherited from Gem::Command

#command, #defaults, #options, #program_name, #summary

Instance Method Summary collapse

Methods inherited from Gem::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_all_gem_names_and_versions, #get_one_gem_name, #get_one_optional_argument, #handle_options, #handles?, #invoke, #invoke_with_build_args, #merge_options, #remove_option, #show_lookup_failure, specific_extra_args, specific_extra_args_hash, #when_invoked

Methods included from UserInteraction

#alert, #alert_error, #alert_warning, #ask, #ask_for_password, #ask_yes_no, #choose_from_list, #say, #terminate_interaction

Methods included from DefaultUserInteraction

ui, #ui, ui=, #ui=, use_ui, #use_ui

Constructor Details

#initializeHelpCommand

:startdoc:



95
96
97
98
99
# File 'lib/rubygems/commands/help_command.rb', line 95

def initialize
  super 'help', "Provide help on the 'gem' command"

  @command_manager = Gem::CommandManager.instance
end

Instance Method Details

#argumentsObject

:nodoc:



101
102
103
104
105
106
107
108
# File 'lib/rubygems/commands/help_command.rb', line 101

def arguments # :nodoc:
  args = "    commands      List all 'gem' commands\n    examples      Show examples of 'gem' usage\n    <command>     Show specific help for <command>\n  EOF\n  return args.gsub(/^\\s+/, '')\nend\n"

#executeObject



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
# File 'lib/rubygems/commands/help_command.rb', line 114

def execute
  arg = options[:args][0]

  if begins? "commands", arg then
    show_commands

  elsif begins? "options", arg then
    say Gem::Command::HELP

  elsif begins? "examples", arg then
    say EXAMPLES

  elsif begins? "platforms", arg then
    say PLATFORMS

  elsif options[:help] then
    show_help

  elsif arg then
    show_command_help arg

  else
    say Gem::Command::HELP
  end
end

#show_command_help(command_name) ⇒ Object

:nodoc:



179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/rubygems/commands/help_command.rb', line 179

def show_command_help command_name # :nodoc:
  command_name = command_name.downcase

  possibilities = @command_manager.find_command_possibilities command_name

  if possibilities.size == 1 then
    command = @command_manager[possibilities.first]
    command.invoke("--help")
  elsif possibilities.size > 1 then
    alert_warning "Ambiguous command #{command_name} (#{possibilities.join(', ')})"
  else
    alert_warning "Unknown command #{command_name}.  Try: gem help commands"
  end
end

#show_commandsObject

:nodoc:



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
170
171
172
173
174
175
176
177
# File 'lib/rubygems/commands/help_command.rb', line 140

def show_commands # :nodoc:
  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|
    command = @command_manager[cmd_name]

    summary =
      if command then
        command.summary
      else
        "[No command found for #{cmd_name}]"
      end

    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")
end

#show_helpObject

:nodoc:



194
195
196
197
198
199
200
201
202
# File 'lib/rubygems/commands/help_command.rb', line 194

def show_help # :nodoc:
  command = @command_manager[options[:help]]
  if command then
    # help with provided command
    command.invoke("--help")
  else
    alert_error "Unknown command #{options[:help]}.  Try 'gem help commands'"
  end
end

#usageObject

:nodoc:



110
111
112
# File 'lib/rubygems/commands/help_command.rb', line 110

def usage # :nodoc:
  "#{program_name} ARGUMENT"
end