summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-06-20 18:19:36 +0000
committerThe Bundler Bot <bot@bundler.io>2017-06-20 18:19:36 +0000
commitde7d488b833ba30cb6fb7b8a37ebf0367c05c196 (patch)
tree193a7cb90110f099bb9b6fd6fd9175534f3784f7
parentdf0e27ff6b8ffea78a52dbec6999950ab32f7af1 (diff)
parent531d52f8ef61177d62191586b5fda9f35b29e5ef (diff)
downloadbundler-de7d488b833ba30cb6fb7b8a37ebf0367c05c196.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.
-rw-r--r--lib/bundler/cli.rb14
-rw-r--r--spec/bundler/cli_spec.rb5
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 838dcb3e08..58a7ce491a 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -621,10 +621,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 f893e7799f..36fd5a6e46 100644
--- a/spec/bundler/cli_spec.rb
+++ b/spec/bundler/cli_spec.rb
@@ -59,6 +59,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