2 # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4 # See LICENSE.txt for permissions.
9 # Mixin methods for --version and --platform Gem::Command options.
10 module Gem::VersionOption
12 # Add the --platform option to the option parser.
13 def add_platform_option(task = command, *wrap)
14 OptionParser.accept Gem::Platform do |value|
15 if value == Gem::Platform::RUBY then
18 Gem::Platform.new value
22 add_option('--platform PLATFORM', Gem::Platform,
23 "Specify the platform of gem to #{task}", *wrap) do
25 unless options[:added_platform] then
26 Gem.platforms = [Gem::Platform::RUBY]
27 options[:added_platform] = true
30 Gem.platforms << value unless Gem.platforms.include? value
34 # Add the --version option to the option parser.
35 def add_version_option(task = command, *wrap)
36 OptionParser.accept Gem::Requirement do |value|
37 Gem::Requirement.new value
40 add_option('-v', '--version VERSION', Gem::Requirement,
41 "Specify version of gem to #{task}", *wrap) do
43 options[:version] = value