2007-11-10 10:48:56 +03:00
|
|
|
require 'rubygems/command'
|
|
|
|
require 'rubygems/local_remote_options'
|
|
|
|
require 'rubygems/version_option'
|
2012-11-29 10:52:18 +04:00
|
|
|
require 'rubygems/package'
|
2007-11-10 10:48:56 +03:00
|
|
|
|
|
|
|
class Gem::Commands::SpecificationCommand < Gem::Command
|
|
|
|
|
|
|
|
include Gem::LocalRemoteOptions
|
|
|
|
include Gem::VersionOption
|
|
|
|
|
|
|
|
def initialize
|
2011-01-19 03:08:49 +03:00
|
|
|
Gem.load_yaml
|
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
super 'specification', 'Display gem specification (in yaml)',
|
2009-06-10 01:38:59 +04:00
|
|
|
:domain => :local, :version => Gem::Requirement.default,
|
|
|
|
:format => :yaml
|
2007-11-10 10:48:56 +03:00
|
|
|
|
|
|
|
add_version_option('examine')
|
|
|
|
add_platform_option
|
2012-11-29 10:52:18 +04:00
|
|
|
add_prerelease_option
|
2007-11-10 10:48:56 +03:00
|
|
|
|
|
|
|
add_option('--all', 'Output specifications for all versions of',
|
|
|
|
'the gem') do |value, options|
|
|
|
|
options[:all] = true
|
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
add_option('--ruby', 'Output ruby format') do |value, options|
|
|
|
|
options[:format] = :ruby
|
|
|
|
end
|
|
|
|
|
2013-07-09 02:41:03 +04:00
|
|
|
add_option('--yaml', 'Output YAML format') do |value, options|
|
2009-06-10 01:38:59 +04:00
|
|
|
options[:format] = :yaml
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option('--marshal', 'Output Marshal format') do |value, options|
|
|
|
|
options[:format] = :marshal
|
|
|
|
end
|
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
add_local_remote_options
|
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
2009-06-10 01: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 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def defaults_str # :nodoc:
|
2009-06-10 01:38:59 +04:00
|
|
|
"--local --version '#{Gem::Requirement.default}' --yaml"
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
2013-09-14 12:59:02 +04:00
|
|
|
def description # :nodoc:
|
|
|
|
<<-EOF
|
|
|
|
The specification command allows you to extract the specification from
|
|
|
|
a gem for examination.
|
|
|
|
|
|
|
|
The specification can be output in YAML, ruby or Marshal formats.
|
|
|
|
|
|
|
|
Specific fields in the specification can be extracted in YAML format:
|
|
|
|
|
|
|
|
$ gem spec rake summary
|
|
|
|
--- Ruby based make-like utility.
|
|
|
|
...
|
|
|
|
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def usage # :nodoc:
|
2009-06-10 01:38:59 +04:00
|
|
|
"#{program_name} [GEMFILE] [FIELD]"
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
specs = []
|
2009-06-10 01: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-11-29 10:52:18 +04:00
|
|
|
case v = options[:version]
|
2012-04-18 04:04:12 +04:00
|
|
|
when String
|
2012-11-29 10:52:18 +04:00
|
|
|
req = Gem::Requirement.create v
|
2012-04-18 04:04:12 +04:00
|
|
|
when Gem::Requirement
|
2012-11-29 10:52:18 +04:00
|
|
|
req = v
|
2012-04-18 04:04:12 +04:00
|
|
|
else
|
2012-11-29 10:52:18 +04:00
|
|
|
raise Gem::CommandLineError, "Unsupported version type: '#{v}'"
|
2012-04-18 04:04:12 +04:00
|
|
|
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
|
2012-11-29 10:52:18 +04:00
|
|
|
dep = Gem::Dependency.new gem, req
|
2012-04-18 04:04:12 +04:00
|
|
|
end
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
field = get_one_optional_argument
|
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
raise Gem::CommandLineError, "--ruby and FIELD are mutually exclusive" if
|
|
|
|
field and options[:format] == :ruby
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
if local? then
|
2008-04-01 02:40:06 +04:00
|
|
|
if File.exist? gem then
|
2012-11-29 10:52:18 +04:00
|
|
|
specs << Gem::Package.new(gem).spec rescue nil
|
2008-04-01 02:40:06 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
if specs.empty? then
|
2011-06-01 07:45:05 +04:00
|
|
|
specs.push(*dep.matching_specs)
|
2008-04-01 02:40:06 +04:00
|
|
|
end
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
if remote? then
|
2012-11-29 10:52:18 +04:00
|
|
|
dep.prerelease = options[:prerelease]
|
|
|
|
found, _ = Gem::SpecFetcher.fetcher.spec_for_dependency dep
|
2008-06-18 02:04:18 +04:00
|
|
|
|
|
|
|
specs.push(*found.map { |spec,| spec })
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
if specs.empty? then
|
2012-11-29 10:52:18 +04:00
|
|
|
alert_error "No gem matching '#{dep}' found"
|
2007-11-10 10:48:56 +03:00
|
|
|
terminate_interaction 1
|
|
|
|
end
|
|
|
|
|
2011-06-01 07:45:05 +04:00
|
|
|
unless options[:all] then
|
2013-09-25 04:53:19 +04:00
|
|
|
specs = [specs.max_by { |s| s.version }]
|
2011-06-01 07:45:05 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
specs.each do |s|
|
2009-06-10 01: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 10:48:56 +03:00
|
|
|
end
|
|
|
|
end
|