2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2007-11-10 02:48:56 -05:00
|
|
|
#--
|
|
|
|
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
|
|
|
# All rights reserved.
|
|
|
|
# See LICENSE.txt for permissions.
|
|
|
|
#++
|
|
|
|
|
|
|
|
require 'rubygems'
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# Mixin methods for --version and --platform Gem::Command options.
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
module Gem::VersionOption
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# Add the --platform option to the option parser.
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def add_platform_option(task = command, *wrap)
|
|
|
|
OptionParser.accept Gem::Platform do |value|
|
|
|
|
if value == Gem::Platform::RUBY then
|
|
|
|
value
|
|
|
|
else
|
|
|
|
Gem::Platform.new value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option('--platform PLATFORM', Gem::Platform,
|
|
|
|
"Specify the platform of gem to #{task}", *wrap) do
|
|
|
|
|value, options|
|
|
|
|
unless options[:added_platform] then
|
2008-04-11 16:57:02 -04:00
|
|
|
Gem.platforms = [Gem::Platform::RUBY]
|
2007-11-10 02:48:56 -05:00
|
|
|
options[:added_platform] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem.platforms << value unless Gem.platforms.include? value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-21 21:52:35 -05:00
|
|
|
##
|
|
|
|
# Add the --prerelease option to the option parser.
|
|
|
|
|
|
|
|
def add_prerelease_option(*wrap)
|
|
|
|
add_option("--[no-]prerelease",
|
|
|
|
"Allow prerelease versions of a gem", *wrap) do |value, options|
|
|
|
|
options[:prerelease] = value
|
2013-09-14 04:59:02 -04:00
|
|
|
options[:explicit_prerelease] = true
|
2010-02-21 21:52:35 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2007-11-10 02:48:56 -05:00
|
|
|
# Add the --version option to the option parser.
|
2010-02-21 21:52:35 -05:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
def add_version_option(task = command, *wrap)
|
|
|
|
OptionParser.accept Gem::Requirement do |value|
|
2013-09-14 04:59:02 -04:00
|
|
|
Gem::Requirement.new(*value.split(/\s*,\s*/))
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
add_option('-v', '--version VERSION', Gem::Requirement,
|
|
|
|
"Specify version of gem to #{task}", *wrap) do
|
|
|
|
|value, options|
|
|
|
|
options[:version] = value
|
2013-09-14 04:59:02 -04:00
|
|
|
|
|
|
|
explicit_prerelease_set = !options[:explicit_prerelease].nil?
|
|
|
|
options[:explicit_prerelease] = false unless explicit_prerelease_set
|
|
|
|
|
|
|
|
options[:prerelease] = value.prerelease? unless
|
|
|
|
options[:explicit_prerelease]
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|