PageRenderTime 67ms CodeModel.GetById 33ms app.highlight 21ms RepoModel.GetById 6ms app.codeStats 0ms

/tools/Ruby/lib/ruby/site_ruby/1.8/rubygems/commands/uninstall_command.rb

http://github.com/agross/netopenspace
Ruby | 88 lines | 66 code | 18 blank | 4 comment | 0 complexity | d64b9885eaa038263d5297e426b83342 MD5 | raw file
 1require 'rubygems/command'
 2require 'rubygems/version_option'
 3require 'rubygems/uninstaller'
 4
 5##
 6# Gem uninstaller command line tool
 7#
 8# See `gem help uninstall`
 9
10class Gem::Commands::UninstallCommand < Gem::Command
11
12  include Gem::VersionOption
13
14  def initialize
15    super 'uninstall', 'Uninstall gems from the local repository',
16          :version => Gem::Requirement.default, :user_install => true
17
18    add_option('-a', '--[no-]all',
19      'Uninstall all matching versions'
20      ) do |value, options|
21      options[:all] = value
22    end
23
24    add_option('-I', '--[no-]ignore-dependencies',
25               'Ignore dependency requirements while',
26               'uninstalling') do |value, options|
27      options[:ignore] = value
28    end
29
30    add_option('-x', '--[no-]executables',
31                 'Uninstall applicable executables without',
32                 'confirmation') do |value, options|
33      options[:executables] = value
34    end
35
36    add_option('-i', '--install-dir DIR',
37               'Directory to uninstall gem from') do |value, options|
38      options[:install_dir] = File.expand_path(value)
39    end
40
41    add_option('-n', '--bindir DIR',
42               'Directory to remove binaries from') do |value, options|
43      options[:bin_dir] = File.expand_path(value)
44    end
45
46    add_option('--[no-]user-install',
47               'Uninstall from user\'s home directory',
48               'in addition to GEM_HOME.') do |value, options|
49      options[:user_install] = value
50    end
51
52    add_option('--[no-]format-executable',
53               'Assume executable names match Ruby\'s prefix and suffix.') do |value, options|
54      options[:format_executable] = value
55    end
56
57    add_version_option
58    add_platform_option
59  end
60
61  def arguments # :nodoc:
62    "GEMNAME       name of gem to uninstall"
63  end
64
65  def defaults_str # :nodoc:
66    "--version '#{Gem::Requirement.default}' --no-force " \
67    "--install-dir #{Gem.dir}\n" \
68    "--user-install"
69  end
70
71  def usage # :nodoc:
72    "#{program_name} GEMNAME [GEMNAME ...]"
73  end
74
75  def execute
76    get_all_gem_names.each do |gem_name|
77      begin
78        Gem::Uninstaller.new(gem_name, options).uninstall
79      rescue Gem::GemNotInHomeException => e
80        spec = e.spec
81        alert("In order to remove #{spec.name}, please execute:\n" \
82              "\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}")
83      end
84    end
85  end
86
87end
88