lib/bundler/cli.rb in bundler-1.1.5 vs lib/bundler/cli.rb in bundler-1.2.0.pre

- old
+ new

@@ -97,11 +97,13 @@ def check ENV['BUNDLE_GEMFILE'] = File.expand_path(options[:gemfile]) if options[:gemfile] Bundler.settings[:path] = File.expand_path(options[:path]) if options[:path] begin - not_installed = Bundler.definition.missing_specs + definition = Bundler.definition + definition.validate_ruby! + not_installed = definition.missing_specs rescue GemNotFound, VersionConflict Bundler.ui.error "Your Gemfile's dependencies could not be satisfied" Bundler.ui.warn "Install missing gems with `bundle install`" exit 1 end @@ -215,11 +217,13 @@ Bundler::Fetcher.disable_endpoint = opts["full-index"] # rubygems plugins sometimes hook into the gem install process Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins) - Installer.install(Bundler.root, Bundler.definition, opts) + definition = Bundler.definition + definition.validate_ruby! + Installer.install(Bundler.root, definition, opts) Bundler.load.cache if Bundler.root.join("vendor/cache").exist? && !options["no-cache"] if Bundler.settings[:path] absolute_path = File.expand_path(Bundler.settings[:path]) relative_path = absolute_path.sub(File.expand_path('.'), '.') @@ -254,24 +258,32 @@ possible versions of the gems in the bundle. D method_option "source", :type => :array, :banner => "Update a specific source (and all gems associated with it)" method_option "local", :type => :boolean, :banner => "Do not attempt to fetch gems remotely and use the gem cache instead" + method_option "quiet", :type => :boolean, :banner => + "Only output warnings and errors." + method_option "full-index", :type => :boolean, :banner => + "Use the rubygems modern index instead of the API endpoint" def update(*gems) sources = Array(options[:source]) + Bundler.ui.be_quiet! if options[:quiet] if gems.empty? && sources.empty? # We're doing a full update Bundler.definition(true) else Bundler.definition(:gems => gems, :sources => sources) end + Bundler::Fetcher.disable_endpoint = options["full-index"] + opts = {"update" => true, "local" => options[:local]} # rubygems plugins sometimes hook into the gem install process Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins) + Bundler.definition.validate_ruby! Installer.install Bundler.root, Bundler.definition, opts Bundler.load.cache if Bundler.root.join("vendor/cache").exist? clean if Bundler.settings[:clean] && Bundler.settings[:path] Bundler.ui.confirm "Your bundle is updated! " + "Use `bundle show [gemname]` to see where a bundled gem is installed." @@ -283,10 +295,11 @@ Calling show with [GEM] will list the exact location of that gem on your machine. D method_option "paths", :type => :boolean, :banner => "List the paths of all gems that are required by your Gemfile." def show(gem_name = nil) + Bundler.definition.validate_ruby! Bundler.load.lock if gem_name Bundler.ui.info locate_gem(gem_name) elsif options[:paths] @@ -312,10 +325,11 @@ method_option "source", :type => :array, :banner => "Check against a specific source" method_option "local", :type => :boolean, :banner => "Do not attempt to fetch gems remotely and use the gem cache instead" def outdated(*gems) sources = Array(options[:source]) + Bundler.definition.validate_ruby! current_specs = Bundler.load.specs if gems.empty? && sources.empty? # We're doing a full update definition = Bundler.definition(true) @@ -360,12 +374,15 @@ Bundler.ui.info "" end desc "cache", "Cache all the gems to vendor/cache", :hide => true method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache." + method_option "all", :type => :boolean, :banner => "Include all sources (including path and git)." def cache + Bundler.definition.validate_ruby! Bundler.definition.resolve_with_cache! + setup_cache_all Bundler.load.cache Bundler.settings[:no_prune] = true if options["no-prune"] Bundler.load.lock rescue GemNotFound => e Bundler.ui.error(e.message) @@ -373,17 +390,19 @@ exit 128 end desc "package", "Locks and then caches all of the gems into vendor/cache" method_option "no-prune", :type => :boolean, :banner => "Don't remove stale gems from the cache." + method_option "all", :type => :boolean, :banner => "Include all sources (including path and git)." long_desc <<-D The package command will copy the .gem files for every gem in the bundle into the directory ./vendor/cache. If you then check that directory into your source control repository, others who check out your source will be able to install the bundle without having to download any additional gems. D def package + setup_cache_all install # TODO: move cache contents here now that all bundles are locked Bundler.load.cache end map %w(pack) => :package @@ -395,10 +414,11 @@ into the systemwide Rubygems repository. D def exec(*) ARGV.shift # remove "exec" + Bundler.definition.validate_ruby! Bundler.load.setup_environment begin # Run Kernel.exec(*ARGV) @@ -425,15 +445,22 @@ If a global setting is superceded by local configuration, this command will show the current value, as well as any superceded values and where they were specified. D - def config(name = nil, *args) + def config(*) values = ARGV.dup values.shift # remove config - values.shift # remove the name + peek = values.shift + + if peek && peek =~ /^\-\-/ + name, scope = values.shift, $' + else + name, scope = peek, "global" + end + unless name Bundler.ui.confirm "Settings are listed in order of priority. The top value will be used.\n" Bundler.settings.all.each do |setting| Bundler.ui.confirm "#{setting}" @@ -445,33 +472,49 @@ Bundler.ui.confirm "" end return end - if values.empty? - Bundler.ui.confirm "Settings for `#{name}` in order of priority. The top value will be used" - with_padding do - Bundler.settings.pretty_values_for(name).each { |line| Bundler.ui.info line } + case scope + when "delete" + Bundler.settings.set_local(name, nil) + Bundler.settings.set_global(name, nil) + when "local", "global" + if values.empty? + Bundler.ui.confirm "Settings for `#{name}` in order of priority. The top value will be used" + with_padding do + Bundler.settings.pretty_values_for(name).each { |line| Bundler.ui.info line } + end + return end - else + locations = Bundler.settings.locations(name) - if local = locations[:local] - Bundler.ui.info "Your application has set #{name} to #{local.inspect}. This will override the " \ - "system value you are currently setting" - end + if scope == "global" + if local = locations[:local] + Bundler.ui.info "Your application has set #{name} to #{local.inspect}. This will override the " \ + "global value you are currently setting" + end - if global = locations[:global] - Bundler.ui.info "You are replacing the current system value of #{name}, which is currently #{global}" + if env = locations[:env] + Bundler.ui.info "You have a bundler environment variable for #{name} set to #{env.inspect}. " \ + "This will take precedence over the global value you are setting" + end + + if global = locations[:global] + Bundler.ui.info "You are replacing the current global value of #{name}, which is currently #{global.inspect}" + end end - if env = locations[:env] - Bundler.ui.info "You have set a bundler environment variable for #{env}. This will take precedence " \ - "over the system value you are setting" + if scope == "local" && local = locations[:local] + Bundler.ui.info "You are replacing the current local value of #{name}, which is currently #{local.inspect}" end - Bundler.settings.set_global(name, values.join(" ")) + Bundler.settings.send("set_#{scope}", name, values.join(" ")) + else + Bundler.ui.error "Invalid scope --#{scope} given. Please use --local or --global." + exit 1 end end desc "open GEM", "Opens the source directory of the given bundled gem" def open(name) @@ -571,20 +614,65 @@ File.expand_path(File.join(File.dirname(__FILE__), 'templates')) end desc "clean", "Cleans up unused gems in your bundler directory" method_option "force", :type => :boolean, :default => false, :banner => - "forces clean even if --path is not set" + "forces clean even if --path is set" def clean if Bundler.settings[:path] || options[:force] Bundler.load.clean else Bundler.ui.error "Can only use bundle clean when --path is set or --force is set" exit 1 end end + desc "platform", "Displays platform compatibility information" + method_option "ruby", :type => :boolean, :default => false, :banner => + "only display ruby related platform information" + def platform + platforms = Bundler.definition.platforms.map {|p| "* #{p}" } + ruby_version = Bundler.definition.ruby_version + output = [] + + if options[:ruby] + if ruby_version + output << ruby_version + else + output << "No ruby version specified" + end + else + output << "Your platform is: #{RUBY_PLATFORM}" + output << "Your app has gems that work on these platforms:\n#{platforms.join("\n")}" + + if ruby_version + output << "Your Gemfile specifies a Ruby version requirement:\n* #{ruby_version}" + + begin + Bundler.definition.validate_ruby! + output << "Your current platform satisfies the Ruby version requirement." + rescue RubyVersionMismatch => e + output << e.message + end + else + output << "Your Gemfile does not specify a Ruby version requirement." + end + end + + Bundler.ui.info output.join("\n\n") + end + private + + def setup_cache_all + if options.key?("all") + Bundler.settings[:cache_all] = options[:all] || nil + elsif Bundler.definition.sources.any? { |s| !s.is_a?(Source::Rubygems) } + Bundler.ui.warn "Your Gemfile contains path and git dependencies. If you want " \ + "to package them as well, please pass the --all flag. This will be the default " \ + "on Bundler 2.0." + end + end def have_groff? !(`which groff` rescue '').empty? end