~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/rubygems/commands/specification_command.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'yaml'
 
2
require 'rubygems/command'
 
3
require 'rubygems/local_remote_options'
 
4
require 'rubygems/version_option'
 
5
require 'rubygems/source_info_cache'
 
6
 
 
7
class Gem::Commands::SpecificationCommand < Gem::Command
 
8
 
 
9
  include Gem::LocalRemoteOptions
 
10
  include Gem::VersionOption
 
11
 
 
12
  def initialize
 
13
    super 'specification', 'Display gem specification (in yaml)',
 
14
          :domain => :local, :version => Gem::Requirement.default
 
15
 
 
16
    add_version_option('examine')
 
17
    add_platform_option
 
18
 
 
19
    add_option('--all', 'Output specifications for all versions of',
 
20
               'the gem') do |value, options|
 
21
      options[:all] = true
 
22
    end
 
23
 
 
24
    add_local_remote_options
 
25
  end
 
26
 
 
27
  def arguments # :nodoc:
 
28
    "GEMFILE       name of gem to show the gemspec for"
 
29
  end
 
30
 
 
31
  def defaults_str # :nodoc:
 
32
    "--local --version '#{Gem::Requirement.default}'"
 
33
  end
 
34
 
 
35
  def usage # :nodoc:
 
36
    "#{program_name} [GEMFILE]"
 
37
  end
 
38
 
 
39
  def execute
 
40
    specs = []
 
41
    gem = get_one_gem_name
 
42
 
 
43
    if local? then
 
44
      source_index = Gem::SourceIndex.from_installed_gems
 
45
      specs.push(*source_index.search(/\A#{gem}\z/, options[:version]))
 
46
    end
 
47
 
 
48
    if remote? then
 
49
      alert_warning "Remote information is not complete\n\n"
 
50
 
 
51
      Gem::SourceInfoCache.cache_data.each do |_,sice|
 
52
        specs.push(*sice.source_index.search(gem, options[:version]))
 
53
      end
 
54
    end
 
55
 
 
56
    if specs.empty? then
 
57
      alert_error "Unknown gem '#{gem}'"
 
58
      terminate_interaction 1
 
59
    end
 
60
 
 
61
    output = lambda { |s| say s.to_yaml; say "\n" }
 
62
 
 
63
    if options[:all] then
 
64
      specs.each(&output)
 
65
    else
 
66
      spec = specs.sort_by { |s| s.version }.last
 
67
      output[spec]
 
68
    end
 
69
  end
 
70
 
 
71
end
 
72