2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2023-03-17 12:36:42 +03:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
#--
|
|
|
|
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
|
|
|
|
# All rights reserved.
|
|
|
|
# See LICENSE.txt for permissions.
|
|
|
|
#++
|
|
|
|
|
2019-04-22 14:56:16 +03:00
|
|
|
require_relative "../rubygems"
|
2007-11-10 10:48:56 +03:00
|
|
|
|
2010-02-22 05:52:35 +03:00
|
|
|
##
|
2007-11-10 10:48:56 +03:00
|
|
|
# Mixin methods for --version and --platform Gem::Command options.
|
2010-02-22 05:52:35 +03:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
module Gem::VersionOption
|
2010-02-22 05:52:35 +03:00
|
|
|
##
|
2007-11-10 10:48:56 +03:00
|
|
|
# Add the --platform option to the option parser.
|
2010-02-22 05:52:35 +03:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def add_platform_option(task = command, *wrap)
|
2021-11-16 14:19:13 +03:00
|
|
|
Gem::OptionParser.accept Gem::Platform do |value|
|
2018-11-21 13:20:47 +03:00
|
|
|
if value == Gem::Platform::RUBY
|
2007-11-10 10:48:56 +03:00
|
|
|
value
|
|
|
|
else
|
|
|
|
Gem::Platform.new value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option("--platform PLATFORM", Gem::Platform,
|
2023-03-16 06:22:51 +03:00
|
|
|
"Specify the platform of gem to #{task}", *wrap) do |value, options|
|
2018-11-21 13:20:47 +03:00
|
|
|
unless options[:added_platform]
|
2008-04-12 00:57:02 +04:00
|
|
|
Gem.platforms = [Gem::Platform::RUBY]
|
2007-11-10 10:48:56 +03:00
|
|
|
options[:added_platform] = true
|
|
|
|
end
|
|
|
|
|
|
|
|
Gem.platforms << value unless Gem.platforms.include? value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-22 05:52:35 +03: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 12:59:02 +04:00
|
|
|
options[:explicit_prerelease] = true
|
2010-02-22 05:52:35 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2007-11-10 10:48:56 +03:00
|
|
|
# Add the --version option to the option parser.
|
2010-02-22 05:52:35 +03:00
|
|
|
|
2007-11-10 10:48:56 +03:00
|
|
|
def add_version_option(task = command, *wrap)
|
2021-11-16 14:19:13 +03:00
|
|
|
Gem::OptionParser.accept Gem::Requirement do |value|
|
2013-09-14 12:59:02 +04:00
|
|
|
Gem::Requirement.new(*value.split(/\s*,\s*/))
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
add_option("-v", "--version VERSION", Gem::Requirement,
|
2023-03-16 06:22:51 +03:00
|
|
|
"Specify version of gem to #{task}", *wrap) do |value, options|
|
2017-10-08 04:32:18 +03:00
|
|
|
# Allow handling for multiple --version operators
|
|
|
|
if options[:version] && !options[:version].none?
|
|
|
|
options[:version].concat([value])
|
|
|
|
else
|
|
|
|
options[:version] = value
|
|
|
|
end
|
2013-09-14 12: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 10:48:56 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-08 10:33:39 +03:00
|
|
|
##
|
|
|
|
# Extract platform given on the command line
|
|
|
|
|
|
|
|
def get_platform_from_requirements(requirements)
|
|
|
|
Gem.platforms[1].to_s if requirements.key? :added_platform
|
|
|
|
end
|
2007-11-10 10:48:56 +03:00
|
|
|
end
|