Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions bundler/lib/bundler/cli/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,26 @@ def run
if value.nil?
warn_unused_scope "Ignoring --#{scope} since no value to set was given"

configured = Bundler.settings.locations(name).any?

if options[:parseable]
if value = Bundler.settings[name]
Bundler.ui.info("#{name}=#{value}")
end
return
if configured
return
else
exit 1
end
end

confirm(name)
return

if configured
return
else
exit 1
end
Comment on lines +91 to +110
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about simplifying this?

if value.nil?
  warn_unused_scope "Ignoring --#{scope} since no value to set was given"
  current_value = Bundler.settings[name]
  if options[:parseable]
    if current_value
      Bundler.ui.info("#{name}=#{current_value}")
    end
  else
    confirm(name)
  end

  if current_value
    return
  else
    exit 1
  end
end

end

Bundler.ui.info(message) if message
Expand Down
4 changes: 3 additions & 1 deletion spec/bundler/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,10 @@ def out_with_macos_man_workaround

context "running a parseable command" do
it "prints no warning" do
bundle "config set foo value", env: { "BUNDLER_VERSION" => bundler_version }
bundle "config get --parseable foo", env: { "BUNDLER_VERSION" => bundler_version }
expect(stdboth).to eq ""
expect(out).to eq "foo=value"
expect(err).to eq ""

bundle "platform --ruby", env: { "BUNDLER_VERSION" => bundler_version }, raise_on_error: false
expect(stdboth).to eq "Could not locate Gemfile"
Expand Down
15 changes: 10 additions & 5 deletions spec/commands/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@

describe "parseable option" do
it "prints an empty string" do
bundle "config get foo --parseable"
bundle "config get foo --parseable", raise_on_error: false

expect(out).to eq ""
expect(last_command).to be_failure
end

it "only prints the value of the config" do
Expand Down Expand Up @@ -501,8 +502,9 @@
it "get" do
ENV["BUNDLE_BAR"] = "bar_val"

bundle "config get foo"
bundle "config get foo", raise_on_error: false
expect(out).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`"
expect(last_command).to be_failure

ENV["BUNDLE_FOO"] = "foo_val"

Expand Down Expand Up @@ -547,7 +549,8 @@

bundle "config unset foo"
expect(out).to eq ""
expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`"
expect(bundle("config get foo", raise_on_error: false)).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`"
expect(last_command).to be_failure

bundle "config set --local foo 1"
bundle "config set --global foo 2"
Expand All @@ -557,7 +560,8 @@
expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nSet for the current user (#{home(".bundle/config")}): \"2\""
bundle "config unset foo --global"
expect(out).to eq ""
expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`"
expect(bundle("config get foo", raise_on_error: false)).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`"
expect(last_command).to be_failure

bundle "config set --local foo 1"
bundle "config set --global foo 2"
Expand All @@ -567,7 +571,8 @@
expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nSet for your local app (#{bundled_app(".bundle/config")}): \"1\""
bundle "config unset foo --local"
expect(out).to eq ""
expect(bundle("config get foo")).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`"
expect(bundle("config get foo", raise_on_error: false)).to eq "Settings for `foo` in order of priority. The top value will be used\nYou have not configured a value for `foo`"
expect(last_command).to be_failure

bundle "config unset foo --local --global", raise_on_error: false
expect(last_command).to be_failure
Expand Down
2 changes: 1 addition & 1 deletion spec/other/major_deprecation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@

describe "old get interface" do
before do
bundle "config waka"
bundle "config waka", raise_on_error: false
end

it "warns", bundler: "4" do
Expand Down