diff options
author | The Bundler Bot <bot@bundler.io> | 2017-06-20 18:19:36 +0000 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-07-17 12:02:31 -0500 |
commit | 571aa4f790dc8849a377566f553533b4759cd95e (patch) | |
tree | 61a1d8b796fbe3cbcb536cd8de5aa92545aec612 | |
parent | d440b9df151149a7bcbcbbf5f4ab7bf5c4ae8ab2 (diff) | |
download | bundler-571aa4f790dc8849a377566f553533b4759cd95e.tar.gz |
Auto merge of #5791 - bundler:seg-verbose-cli-print-no-defaults, r=colby-swandale
[CLI] Dont print defaults in the command printed with --verbose
### What was the end-user problem that led to this PR?
The problem was that running `bundle lock --verbose` would print
Running `bundle lock --add-platform --remove-platform --verbose` with bundler 1.15.1
even though the platform flags were never specified. This was surfaced by https://github.com/bundler/bundler/pull/5724, which will be fixed by this PR.
### Was was your diagnosis of the problem?
My diagnosis was that default values of options were being printed.
### What is your fix for the problem, implemented in this PR?
My fix is to filter out the default values before getting Thor
### Why did you choose this fix out of the possible options?
I chose this fix because there is no way, within the `CLI` instance, to tell which flags the user has explicitly given, so I felt that filtering out those options that had default values was the next-best thing.
(cherry picked from commit de7d488b833ba30cb6fb7b8a37ebf0367c05c196)
# Conflicts:
# lib/bundler/cli.rb
-rw-r--r-- | lib/bundler/cli.rb | 14 | ||||
-rw-r--r-- | spec/bundler/cli_spec.rb | 5 |
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index c55e2a9a56..7110949fda 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -614,10 +614,16 @@ module Bundler def print_command return unless ENV["BUNDLE_POSTIT_TRAMPOLINING_VERSION"] || Bundler.ui.debug? _, _, config = @_initializer - current_command = config[:current_command].name - return if %w(exec version check platform show help).include?(current_command) - command = ["bundle", current_command] + args - command << Thor::Options.to_switches(options) + current_command = config[:current_command] + command_name = current_command.name + return if %w(exec version check platform show help).include?(command_name) + command = ["bundle", command_name] + args + options_to_print = options.dup + options_to_print.delete_if do |k, v| + next unless o = current_command.options[k] + o.default == v + end + command << Thor::Options.to_switches(options_to_print.sort_by(&:first)).strip command.reject!(&:empty?) Bundler.ui.info "Running `#{command * " "}` with bundler #{Bundler::VERSION}" end diff --git a/spec/bundler/cli_spec.rb b/spec/bundler/cli_spec.rb index ec1d384851..4963698c8e 100644 --- a/spec/bundler/cli_spec.rb +++ b/spec/bundler/cli_spec.rb @@ -60,6 +60,11 @@ RSpec.describe "bundle executable" do bundle! "config", :verbose => true expect(out).to start_with("Running `bundle config --verbose` with bundler #{Bundler::VERSION}") end + + it "doesn't print defaults" do + install_gemfile! "", :verbose => true + expect(out).to start_with("Running `bundle install --no-color --retry 0 --verbose` with bundler #{Bundler::VERSION}") + end end describe "printing the outdated warning" do |