1#-- 2# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others. 3# All rights reserved. 4# See LICENSE.txt for permissions. 5#++ 6 7require 'rubygems' 8 9## 10# Mixin methods for --version and --platform Gem::Command options. 11 12module Gem::VersionOption 13 14 ## 15 # Add the --platform option to the option parser. 16 17 def add_platform_option(task = command, *wrap) 18 OptionParser.accept Gem::Platform do |value| 19 if value == Gem::Platform::RUBY then 20 value 21 else 22 Gem::Platform.new value 23 end 24 end 25 26 add_option('--platform PLATFORM', Gem::Platform, 27 "Specify the platform of gem to #{task}", *wrap) do 28 |value, options| 29 unless options[:added_platform] then 30 Gem.platforms = [Gem::Platform::RUBY] 31 options[:added_platform] = true 32 end 33 34 Gem.platforms << value unless Gem.platforms.include? value 35 end 36 end 37 38 ## 39 # Add the --prerelease option to the option parser. 40 41 def add_prerelease_option(*wrap) 42 add_option("--[no-]prerelease", 43 "Allow prerelease versions of a gem", *wrap) do |value, options| 44 options[:prerelease] = value 45 end 46 end 47 48 ## 49 # Add the --version option to the option parser. 50 51 def add_version_option(task = command, *wrap) 52 OptionParser.accept Gem::Requirement do |value| 53 Gem::Requirement.new value 54 end 55 56 add_option('-v', '--version VERSION', Gem::Requirement, 57 "Specify version of gem to #{task}", *wrap) do 58 |value, options| 59 options[:version] = value 60 options[:prerelease] = true if value.prerelease? 61 end 62 end 63 64end 65 66