2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/local_remote_options'
|
|
|
|
require 'rubygems/version_option'
|
2008-03-31 18:40:06 -04:00
|
|
|
require 'rubygems/format'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
class Gem::Commands::SpecificationCommand < Gem::Command
|
|
|
|
|
|
|
|
include Gem::LocalRemoteOptions
|
|
|
|
include Gem::VersionOption
|
|
|
|
|
|
|
|
def initialize
|
2011-01-18 19:08:49 -05:00
|
|
|
Gem.load_yaml
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
super 'specification', 'Display gem specification (in yaml)',
|
2009-06-09 17:38:59 -04:00
|
|
|
:domain => :local, :version => Gem::Requirement.default,
|
|
|
|
:format => :yaml
|
2007-11-10 02:48:56 -05:00
|
|
|
|
|
|
|
add_version_option('examine')
|
|
|
|
add_platform_option
|
|
|
|
|
|
|
|
add_option('--all', 'Output specifications for all versions of',
|
|
|
|
'the gem') do |value, options|
|
|
|
|
options[:all] = true
|
|
|
|
end
|
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
add_option('--ruby', 'Output ruby format') do |value, options|
|
|
|
|
options[:format] = :ruby
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option('--yaml', 'Output RUBY format') do |value, options|
|
|
|
|
options[:format] = :yaml
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option('--marshal', 'Output Marshal format') do |value, options|
|
|
|
|
options[:format] = :marshal
|
|
|
|
end
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
add_local_remote_options
|
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
2009-06-09 17:38:59 -04:00
|
|
|
<<-ARGS
|
|
|
|
GEMFILE name of gem to show the gemspec for
|
|
|
|
FIELD name of gemspec field to show
|
|
|
|
ARGS
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def defaults_str # :nodoc:
|
2009-06-09 17:38:59 -04:00
|
|
|
"--local --version '#{Gem::Requirement.default}' --yaml"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def usage # :nodoc:
|
2009-06-09 17:38:59 -04:00
|
|
|
"#{program_name} [GEMFILE] [FIELD]"
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
specs = []
|
2009-06-09 17:38:59 -04:00
|
|
|
gem = options[:args].shift
|
|
|
|
|
|
|
|
unless gem then
|
|
|
|
raise Gem::CommandLineError,
|
|
|
|
"Please specify a gem name or file on the command line"
|
|
|
|
end
|
|
|
|
|
2012-04-17 20:04:12 -04:00
|
|
|
case options[:version]
|
|
|
|
when String
|
|
|
|
req = Gem::Requirement.parse options[:version]
|
|
|
|
when Gem::Requirement
|
|
|
|
req = options[:version]
|
|
|
|
else
|
|
|
|
raise Gem::CommandLineError, "Unsupported version type: #{options[:version]}"
|
|
|
|
end
|
|
|
|
|
|
|
|
if !req.none? and options[:all]
|
|
|
|
alert_error "Specify --all or -v, not both"
|
|
|
|
terminate_interaction 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if options[:all]
|
|
|
|
dep = Gem::Dependency.new gem
|
|
|
|
else
|
|
|
|
dep = Gem::Dependency.new gem, options[:version]
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2009-06-09 17:38:59 -04:00
|
|
|
field = get_one_optional_argument
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
raise Gem::CommandLineError, "--ruby and FIELD are mutually exclusive" if
|
|
|
|
field and options[:format] == :ruby
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
if local? then
|
2008-03-31 18:40:06 -04:00
|
|
|
if File.exist? gem then
|
|
|
|
specs << Gem::Format.from_file_by_path(gem).spec rescue nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if specs.empty? then
|
2011-05-31 23:45:05 -04:00
|
|
|
specs.push(*dep.matching_specs)
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if remote? then
|
2012-04-17 20:04:12 -04:00
|
|
|
found = Gem::SpecFetcher.fetcher.fetch dep, true
|
|
|
|
|
|
|
|
if dep.prerelease? or options[:prerelease]
|
|
|
|
found += Gem::SpecFetcher.fetcher.fetch dep, false, true, true
|
|
|
|
end
|
2008-06-17 18:04:18 -04:00
|
|
|
|
|
|
|
specs.push(*found.map { |spec,| spec })
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if specs.empty? then
|
|
|
|
alert_error "Unknown gem '#{gem}'"
|
|
|
|
terminate_interaction 1
|
|
|
|
end
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
unless options[:all] then
|
|
|
|
specs = [specs.sort_by { |s| s.version }.last]
|
|
|
|
end
|
|
|
|
|
|
|
|
specs.each do |s|
|
2009-06-09 17:38:59 -04:00
|
|
|
s = s.send field if field
|
|
|
|
|
|
|
|
say case options[:format]
|
|
|
|
when :ruby then s.to_ruby
|
|
|
|
when :marshal then Marshal.dump s
|
|
|
|
else s.to_yaml
|
|
|
|
end
|
|
|
|
|
|
|
|
say "\n"
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|