Class: Gem::Commands::ExecCommand

Inherits:
Gem::Command show all
Includes:
VersionOption
Defined in:
lib/rubygems/commands/exec_command.rb

Instance Attribute Summary

Attributes inherited from Gem::Command

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

Instance Method Summary collapse

Methods included from VersionOption

#add_platform_option, #add_prerelease_option, #add_version_option, #get_platform_from_requirements

Methods inherited from Gem::Command

add_common_option, #add_extra_args, #add_option, add_specific_extra_args, #begins?, build_args, build_args=, #check_deprecated_options, common_options, #deprecate_option, #deprecated?, extra_args, extra_args=, #extract_gem_name_and_version, #get_all_gem_names, #get_all_gem_names_and_versions, #get_one_gem_name, #get_one_optional_argument, #handles?, #invoke, #invoke_with_build_args, #merge_options, #remove_option, #show_help, #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, #verbose

Methods included from DefaultUserInteraction

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

Methods included from Text

#clean_text, #format_text, #levenshtein_distance, #min3, #truncate_text

Constructor Details

#initializeExecCommand

Returns a new instance of ExecCommand.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubygems/commands/exec_command.rb', line 12

def initialize
  super "exec", "Run a command from a gem", {
    version: Gem::Requirement.default,
  }

  add_version_option
  add_prerelease_option "to be installed"

  add_option "-g", "--gem GEM", "run the executable from the given gem" do |value, options|
    options[:gem_name] = value
  end

  add_option(:"Install/Update", "--conservative",
    "Prefer the most recent installed version, ",
    "rather than the latest version overall") do |_value, options|
    options[:conservative] = true
  end
end

Instance Method Details

#argumentsObject

:nodoc:



31
32
33
# File 'lib/rubygems/commands/exec_command.rb', line 31

def arguments # :nodoc:
  "COMMAND  the executable command to run"
end

#defaults_strObject

:nodoc:



35
36
37
# File 'lib/rubygems/commands/exec_command.rb', line 35

def defaults_str # :nodoc:
  "--version '#{Gem::Requirement.default}'"
end

#descriptionObject

:nodoc:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubygems/commands/exec_command.rb', line 39

def description # :nodoc:
  <<-EOF
The exec command handles installing (if necessary) and running an executable
from a gem, regardless of whether that gem is currently installed.

The exec command can be thought of as a shortcut to running `gem install` and
then the executable from the installed gem.

For example, `gem exec rails new .` will run `rails new .` in the current
directory, without having to manually run `gem install rails`.
Additionally, the exec command ensures the most recent version of the gem
is used (unless run with `--conservative`), and that the gem is not installed
to the same gem path as user-installed gems.
  EOF
end

#executeObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rubygems/commands/exec_command.rb', line 59

def execute
  check_executable

  print_command
  if options[:gem_name] == "gem" && options[:executable] == "gem"
    set_gem_exec_install_paths
    Gem::GemRunner.new.run options[:args]
    return
  elsif options[:conservative]
    install_if_needed
  else
    install
    activate!
  end

  load!
end

#usageObject

:nodoc:



55
56
57
# File 'lib/rubygems/commands/exec_command.rb', line 55

def usage # :nodoc:
  "#{program_name} [options --] COMMAND [args]"
end