~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/rubygems/version_option.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
7
require 'rubygems'
 
8
 
 
9
# Mixin methods for --version and --platform Gem::Command options.
 
10
module Gem::VersionOption
 
11
 
 
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
 
16
        value
 
17
      else
 
18
        Gem::Platform.new value
 
19
      end
 
20
    end
 
21
 
 
22
    add_option('--platform PLATFORM', Gem::Platform,
 
23
               "Specify the platform of gem to #{task}", *wrap) do
 
24
                 |value, options|
 
25
      unless options[:added_platform] then
 
26
        Gem.platforms.clear
 
27
        Gem.platforms << Gem::Platform::RUBY
 
28
        options[:added_platform] = true
 
29
      end
 
30
 
 
31
      Gem.platforms << value unless Gem.platforms.include? value
 
32
    end
 
33
  end
 
34
 
 
35
  # Add the --version option to the option parser.
 
36
  def add_version_option(task = command, *wrap)
 
37
    OptionParser.accept Gem::Requirement do |value|
 
38
      Gem::Requirement.new value
 
39
    end
 
40
 
 
41
    add_option('-v', '--version VERSION', Gem::Requirement,
 
42
               "Specify version of gem to #{task}", *wrap) do
 
43
                 |value, options|
 
44
      options[:version] = value
 
45
    end
 
46
  end
 
47
 
 
48
end
 
49