| Class | Gem::Commands::SpecificationCommand |
| In: |
lib/rubygems/commands/specification_command.rb
|
| Parent: | Gem::Command |
# File lib/rubygems/commands/specification_command.rb, line 11
11: def initialize
12: Gem.load_yaml
13:
14: super 'specification', 'Display gem specification (in yaml)',
15: :domain => :local, :version => Gem::Requirement.default,
16: :format => :yaml
17:
18: add_version_option('examine')
19: add_platform_option
20:
21: add_option('--all', 'Output specifications for all versions of',
22: 'the gem') do |value, options|
23: options[:all] = true
24: end
25:
26: add_option('--ruby', 'Output ruby format') do |value, options|
27: options[:format] = :ruby
28: end
29:
30: add_option('--yaml', 'Output RUBY format') do |value, options|
31: options[:format] = :yaml
32: end
33:
34: add_option('--marshal', 'Output Marshal format') do |value, options|
35: options[:format] = :marshal
36: end
37:
38: add_local_remote_options
39: end
# File lib/rubygems/commands/specification_command.rb, line 57
57: def execute
58: specs = []
59: gem = options[:args].shift
60:
61: unless gem then
62: raise Gem::CommandLineError,
63: "Please specify a gem name or file on the command line"
64: end
65:
66: dep = Gem::Dependency.new gem, options[:version]
67:
68: field = get_one_optional_argument
69:
70: raise Gem::CommandLineError, "--ruby and FIELD are mutually exclusive" if
71: field and options[:format] == :ruby
72:
73: if local? then
74: if File.exist? gem then
75: specs << Gem::Format.from_file_by_path(gem).spec rescue nil
76: end
77:
78: if specs.empty? then
79: specs.push(*dep.matching_specs)
80: end
81: end
82:
83: if remote? then
84: found = Gem::SpecFetcher.fetcher.fetch dep
85:
86: specs.push(*found.map { |spec,| spec })
87: end
88:
89: if specs.empty? then
90: alert_error "Unknown gem '#{gem}'"
91: terminate_interaction 1
92: end
93:
94: unless options[:all] then
95: specs = [specs.sort_by { |s| s.version }.last]
96: end
97:
98: specs.each do |s|
99: s = s.send field if field
100:
101: say case options[:format]
102: when :ruby then s.to_ruby
103: when :marshal then Marshal.dump s
104: else s.to_yaml
105: end
106:
107: say "\n"
108: end
109: end