Class: Gem::Commands::ImportCommand

Inherits:
InstallCommand
  • Object
show all
Defined in:
lib/rubygems/commands/import_command.rb

Instance Method Summary collapse

Constructor Details

#initializeImportCommand

Returns a new instance of ImportCommand.



6
7
8
# File 'lib/rubygems/commands/import_command.rb', line 6

def initialize
  super
end

Instance Method Details

#argumentsObject

:nodoc:



10
11
12
# File 'lib/rubygems/commands/import_command.rb', line 10

def arguments # :nodoc:
  "GEM_LIST  Yaml file with the gems to install"
end

#executeObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubygems/commands/import_command.rb', line 18

def execute
  gemspec = get_one_gem_name
  
  unless gemspec then
    raise Gem::CommandLineError,
          "Please specify a gem yaml file on the command line"
  end
  
  unless File.exist?(gemspec) then
    raise Gem::CommandLineError,
          "Specified file #{gemspec} does not exist"
  end

  options[:ignore_dependencies] = true
  installed_gems = []

  data = YAML.load_file( gemspec )
  data['gems'].each do |g|
    begin
      inst = Gem::DependencyInstaller.new options
      inst.install g[:name], g[:version]
          
      inst.installed_gems.each do |spec|
        say "Successfully installed #{spec.full_name}"
      end
          
      installed_gems.push(*inst.installed_gems)
    rescue Gem::InstallError => e
      alert_error "Error installing #{gem_name}:\n\t#{e.message}"
      exit_code |= 1
    rescue Gem::GemNotFoundException => e
      alert_error e.message
      exit_code |= 2
    end
  end
end

#usageObject

:nodoc:



14
15
16
# File 'lib/rubygems/commands/import_command.rb', line 14

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