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# forward-declare 10 11module Gem::Security # :nodoc: 12 class Policy # :nodoc: 13 end 14end 15 16## 17# Mixin methods for install and update options for Gem::Commands 18 19module Gem::InstallUpdateOptions 20 21 ## 22 # Add the install/update options to the option parser. 23 24 def add_install_update_options 25 # TODO: use @parser.accept 26 OptionParser.accept Gem::Security::Policy do |value| 27 require 'rubygems/security' 28 29 value = Gem::Security::Policies[value] 30 valid = Gem::Security::Policies.keys.sort 31 message = "#{value} (#{valid.join ', '} are valid)" 32 raise OptionParser::InvalidArgument, message if value.nil? 33 value 34 end 35 36 add_option(:"Install/Update", '-i', '--install-dir DIR', 37 'Gem repository directory to get installed', 38 'gems') do |value, options| 39 options[:install_dir] = File.expand_path(value) 40 end 41 42 add_option(:"Install/Update", '-n', '--bindir DIR', 43 'Directory where binary files are', 44 'located') do |value, options| 45 options[:bin_dir] = File.expand_path(value) 46 end 47 48 add_option(:"Install/Update", '--[no-]document [TYPES]', Array, 49 'Generate documentation for installed gems', 50 'List the documentation types you wish to', 51 'generate. For example: rdoc,ri') do |value, options| 52 options[:document] = case value 53 when nil then %w[ri] 54 when false then [] 55 else value 56 end 57 end 58 59 add_option(:"Install/Update", '-N', '--no-document', 60 'Disable documentation generation') do |value, options| 61 options[:document] = [] 62 end 63 64 add_option(:Deprecated, '--[no-]rdoc', 65 'Generate RDoc for installed gems', 66 'Use --document instead') do |value, options| 67 if value then 68 options[:document] << 'rdoc' 69 else 70 options[:document].delete 'rdoc' 71 end 72 73 options[:document].uniq! 74 end 75 76 add_option(:Deprecated, '--[no-]ri', 77 'Generate ri data for installed gems.', 78 'Use --document instead') do |value, options| 79 if value then 80 options[:document] << 'ri' 81 else 82 options[:document].delete 'ri' 83 end 84 85 options[:document].uniq! 86 end 87 88 add_option(:"Install/Update", '-E', '--[no-]env-shebang', 89 "Rewrite the shebang line on installed", 90 "scripts to use /usr/bin/env") do |value, options| 91 options[:env_shebang] = value 92 end 93 94 add_option(:"Install/Update", '-f', '--[no-]force', 95 'Force gem to install, bypassing dependency', 96 'checks') do |value, options| 97 options[:force] = value 98 end 99 100 add_option(:"Install/Update", '-w', '--[no-]wrappers', 101 'Use bin wrappers for executables', 102 'Not available on dosish platforms') do |value, options| 103 options[:wrappers] = value 104 end 105 106 add_option(:"Install/Update", '-P', '--trust-policy POLICY', 107 Gem::Security::Policy, 108 'Specify gem trust policy') do |value, options| 109 options[:security_policy] = value 110 end 111 112 add_option(:"Install/Update", '--ignore-dependencies', 113 'Do not install any required dependent gems') do |value, options| 114 options[:ignore_dependencies] = value 115 end 116 117 add_option(:"Install/Update", '--[no-]format-executable', 118 'Make installed executable names match ruby.', 119 'If ruby is ruby18, foo_exec will be', 120 'foo_exec18') do |value, options| 121 options[:format_executable] = value 122 end 123 124 add_option(:"Install/Update", '--[no-]user-install', 125 'Install in user\'s home directory instead', 126 'of GEM_HOME.') do |value, options| 127 options[:user_install] = value 128 end 129 130 add_option(:"Install/Update", "--development", 131 "Install additional development", 132 "dependencies") do |value, options| 133 options[:development] = true 134 options[:dev_shallow] = true 135 end 136 137 add_option(:"Install/Update", "--development-all", 138 "Install development dependencies for all", 139 "gems (including dev deps themselves)") do |value, options| 140 options[:development] = true 141 options[:dev_shallow] = false 142 end 143 144 add_option(:"Install/Update", "--conservative", 145 "Don't attempt to upgrade gems already", 146 "meeting version requirement") do |value, options| 147 options[:conservative] = true 148 options[:minimal_deps] = true 149 end 150 151 add_option(:"Install/Update", "--minimal-deps", 152 "Don't upgrade any dependencies that already", 153 "meet version requirements") do |value, options| 154 options[:minimal_deps] = true 155 end 156 end 157 158 ## 159 # Default options for the gem install command. 160 161 def install_update_defaults_str 162 '--document=rdoc,ri --wrappers' 163 end 164 165end 166 167