components/ruby/Solaris/scripts/gemwhich
changeset 199 b87534be1a76
equal deleted inserted replaced
198:172fc01ce997 199:b87534be1a76
       
     1 #!/usr/ruby/1.8/bin/ruby
       
     2 #
       
     3 # CDDL HEADER START
       
     4 #
       
     5 # The contents of this file are subject to the terms of the
       
     6 # Common Development and Distribution License (the "License").
       
     7 # You may not use this file except in compliance with the License.
       
     8 #
       
     9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10 # or http://www.opensolaris.org/os/licensing.
       
    11 # See the License for the specific language governing permissions
       
    12 # and limitations under the License.
       
    13 #
       
    14 # When distributing Covered Code, include this CDDL HEADER in each
       
    15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16 # If applicable, add the following below this CDDL HEADER, with the
       
    17 # fields enclosed by brackets "[]" replaced with your own identifying
       
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    19 #
       
    20 # CDDL HEADER END
       
    21 #
       
    22  
       
    23 #
       
    24 # Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
       
    25 #
       
    26 
       
    27 require 'optparse'
       
    28 
       
    29 pass_on_opts = ["which"]
       
    30 pass_on_opts << "--no-verbose"
       
    31 suppress = false
       
    32 deprecation_msg =  "WARNING: gemwhich has been deprecated and will be removed in a future release of Solaris, use 'gem which' instead. (use '-s' to suppress these warnings)\n\n"
       
    33 
       
    34 options = OptionParser.new do |opts|
       
    35   opts.banner = "gemwhich -- Find the location of a library module."
       
    36   opts.separator ""
       
    37   opts.separator "Usage: gemwhich [options] [libname]..."
       
    38 
       
    39   opts.on('-a', '--all',
       
    40          "Show all matching files"
       
    41      ) do |value|
       
    42        pass_on_opts  << '-a'
       
    43   end
       
    44 
       
    45   opts.on('-g', '--gems-first',
       
    46           "Search GEM libraries before non-GEMs"
       
    47         ) do |value|
       
    48           pass_on_opts << '-g'
       
    49         end
       
    50 
       
    51   opts.on_tail('-v', '--verbose',
       
    52          "Enable verbose output"
       
    53      ) do |value|
       
    54       pass_on_opts << '-v'
       
    55   end
       
    56 
       
    57   opts.on_tail('-s', '--suppress-warnings',
       
    58          "Suppress deprecation warning"
       
    59      ) do |value|
       
    60        suppress = true
       
    61    end
       
    62 
       
    63   opts.on_tail('-h', '--help', "Display this help message"
       
    64      ) do
       
    65       print deprecation_msg
       
    66       puts opts
       
    67       exit
       
    68   end
       
    69 
       
    70 end
       
    71 
       
    72 
       
    73 ARGV << '-h' if ARGV.empty?
       
    74 
       
    75 begin
       
    76   options.parse!(ARGV)
       
    77 rescue OptionParser::InvalidArgument => err
       
    78   puts options
       
    79   puts
       
    80   puts err.message
       
    81   exit(-1)
       
    82 end
       
    83 
       
    84 ARGV.each do |arg|
       
    85   pass_on_opts << arg
       
    86 end
       
    87 
       
    88 print deprecation_msg unless suppress
       
    89 
       
    90 system("gem", *pass_on_opts)