diff options
author | The Bundler Bot <bot@bundler.io> | 2017-04-15 01:15:58 +0000 |
---|---|---|
committer | The Bundler Bot <bot@bundler.io> | 2017-04-15 01:15:58 +0000 |
commit | 7ce45d7702479542975a98762cc33982d8fb6ee7 (patch) | |
tree | fd98f2bc089eab2a65dd89ad9d431f1d185d3b8a | |
parent | 3b62843d99648b803c0210a09b54db36dbf5e1ab (diff) | |
parent | 3c52af901fb41b5d82a53ec5300e53b700404d50 (diff) | |
download | bundler-7ce45d7702479542975a98762cc33982d8fb6ee7.tar.gz |
Auto merge of #5306 - colby-swandale:bundler-config-parseable-flag, r=segiddins
Bundler config parseable flag
This PR is continuing on from #4919. This adds an option to `bundle config` called `parseable` that prints the value of config without the verbose. Example:
$ bundle config foo --parseable
bar
Closes #4919
-rw-r--r-- | lib/bundler/cli.rb | 1 | ||||
-rw-r--r-- | lib/bundler/cli/config.rb | 30 | ||||
-rw-r--r-- | spec/commands/config_spec.rb | 89 |
3 files changed, 114 insertions, 6 deletions
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 9c49858e00..ba329b78cb 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -373,6 +373,7 @@ module Bundler will show the current value, as well as any superceded values and where they were specified. D + method_option "parseable", :type => :boolean, :banner => "Use minimal formatting for more parseable output" def config(*args) require "bundler/cli/config" Config.new(options, args, self).run diff --git a/lib/bundler/cli/config.rb b/lib/bundler/cli/config.rb index 32724f687d..e8f13620ec 100644 --- a/lib/bundler/cli/config.rb +++ b/lib/bundler/cli/config.rb @@ -33,6 +33,13 @@ module Bundler end if args.empty? + if options[:parseable] + if value = Bundler.settings[name] + Bundler.ui.info("#{name}=#{value}") + end + return + end + confirm(name) return end @@ -44,11 +51,20 @@ module Bundler private def confirm_all - 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}" - show_pretty_values_for(setting) - Bundler.ui.confirm "" + if @options[:parseable] + thor.with_padding do + Bundler.settings.all.each do |setting| + val = Bundler.settings[setting] + Bundler.ui.info "#{setting}=#{val}" + end + end + else + 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}" + show_pretty_values_for(setting) + Bundler.ui.confirm "" + end end end @@ -68,7 +84,9 @@ module Bundler def message locations = Bundler.settings.locations(name) - if scope == "global" + if @options[:parseable] + "#{name}=#{new_value}" if new_value + elsif scope == "global" if locations[:local] "Your application has set #{name} to #{locations[:local].inspect}. " \ "This will override the global value you are currently setting" diff --git a/spec/commands/config_spec.rb b/spec/commands/config_spec.rb index ea0d2a786b..a3ca696ec1 100644 --- a/spec/commands/config_spec.rb +++ b/spec/commands/config_spec.rb @@ -9,6 +9,40 @@ RSpec.describe ".bundle/config" do G end + describe "config" do + before { bundle "config foo bar" } + + it "prints a detailed report of local and user configuration" do + bundle "config" + + expect(out).to include("Settings are listed in order of priority. The top value will be used") + expect(out).to include("foo\nSet for the current user") + expect(out).to include(": \"bar\"") + end + + context "given --parseable flag" do + it "prints a minimal report of local and user configuration" do + bundle "config --parseable" + expect(out).to include("foo=bar") + end + + context "with global config" do + it "prints config assigned to local scope" do + bundle "config --local foo bar2" + bundle "config --parseable" + expect(out).to include("foo=bar2") + end + end + + context "with env overwrite" do + it "prints config with env" do + bundle "config --parseable", :env => { "BUNDLE_FOO" => "bar3" } + expect(out).to include("foo=bar3") + end + end + end + end + describe "BUNDLE_APP_CONFIG" do it "can be moved with an environment variable" do ENV["BUNDLE_APP_CONFIG"] = tmp("foo/bar").to_s @@ -102,6 +136,23 @@ RSpec.describe ".bundle/config" do run "puts Bundler.settings['local.foo']" expect(out).to eq(File.expand_path(Dir.pwd + "/..")) end + + it "saves with parseable option" do + bundle "config --global --parseable foo value" + expect(out).to eq("foo=value") + run "puts Bundler.settings['foo']" + expect(out).to eq("value") + end + + context "when replacing a current value with the parseable flag" do + before { bundle "config --global foo value" } + it "prints the current value in a parseable format" do + bundle "config --global --parseable foo value2" + expect(out).to eq "foo=value2" + run "puts Bundler.settings['foo']" + expect(out).to eq("value2") + end + end end describe "local" do @@ -147,6 +198,14 @@ RSpec.describe ".bundle/config" do run "puts Bundler.settings['local.foo']" expect(out).to eq(File.expand_path(Dir.pwd + "/..")) end + + it "can be deleted with parseable option" do + bundle "config --local foo value" + bundle "config --delete --parseable foo" + expect(out).to eq "" + run "puts Bundler.settings['foo'] == nil" + expect(out).to eq("true") + end end describe "env" do @@ -187,6 +246,36 @@ RSpec.describe ".bundle/config" do end end + describe "parseable option" do + it "prints an empty string" do + bundle "config foo --parseable" + + expect(out).to eq "" + end + + it "only prints the value of the config" do + bundle "config foo local" + bundle "config foo --parseable" + + expect(out).to eq "foo=local" + end + + it "can print global config" do + bundle "config --global bar value" + bundle "config bar --parseable" + + expect(out).to eq "bar=value" + end + + it "preferes local config over global" do + bundle "config --local bar value2" + bundle "config --global bar value" + bundle "config bar --parseable" + + expect(out).to eq "bar=value2" + end + end + describe "gem mirrors" do before(:each) { bundle :install } |