summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2017-05-27 09:01:20 +0000
committerThe Bundler Bot <bot@bundler.io>2017-05-27 09:01:20 +0000
commitc49ca61e05ceb45406f3eb04b63960873b610279 (patch)
treea8564c6cca811079c30df5aa05cf80389b0de259
parent54c51729e4776c3d07992deaedb8ec2788cb35ae (diff)
parenta5c83b88e0422fef0706e950751bace63bcdcfda (diff)
downloadbundler-c49ca61e05ceb45406f3eb04b63960873b610279.tar.gz
Auto merge of #5665 - bundler:colby/stderr-feature, r=indirect
Print errors to stderr As we discussed, i'm going to start porting over features from the 2-0-dev branch into feature flags. This PR adds the feature to print bundler errors to `stderr` instead of `stdout`. I had a look to see how feature flags worked and i think i have the idea down but let me know if i missed something. Thanks! \cc @segiddins @indirect
-rw-r--r--lib/bundler/feature_flag.rb1
-rw-r--r--lib/bundler/settings.rb1
-rw-r--r--lib/bundler/ui/shell.rb11
-rw-r--r--man/bundle-config.ronn2
-rw-r--r--spec/bundler/ui/shell_spec.rb49
5 files changed, 62 insertions, 2 deletions
diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb
index 150cac1e67..5ee69f538c 100644
--- a/lib/bundler/feature_flag.rb
+++ b/lib/bundler/feature_flag.rb
@@ -17,6 +17,7 @@ module Bundler
settings_flag(:allow_offline_install) { bundler_2_mode? }
settings_flag(:only_update_to_newer_versions) { bundler_2_mode? }
settings_flag(:plugins) { @bundler_version >= Gem::Version.new("1.14") }
+ settings_flag(:error_on_stderr) { bundler_2_mode? }
def initialize(bundler_version)
@bundler_version = Gem::Version.create(bundler_version)
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index 62c21a2ecb..9a93eebf83 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -27,6 +27,7 @@ module Bundler
only_update_to_newer_versions
plugins
silence_root_warning
+ error_on_stderr
).freeze
NUMBER_KEYS = %w(
diff --git a/lib/bundler/ui/shell.rb b/lib/bundler/ui/shell.rb
index 87a92471fb..5d4fd76acb 100644
--- a/lib/bundler/ui/shell.rb
+++ b/lib/bundler/ui/shell.rb
@@ -9,7 +9,7 @@ module Bundler
attr_writer :shell
def initialize(options = {})
- if options["no-color"] || !STDOUT.tty?
+ if options["no-color"] || !$stdout.tty?
Thor::Base.shell = Thor::Shell::Basic
end
@shell = Thor::Base.shell.new
@@ -36,7 +36,9 @@ module Bundler
end
def error(msg, newline = nil)
- tell_me(msg, :red, newline) if level("error")
+ return unless level("error")
+ return tell_err(msg, :red, newline) if Bundler.feature_flag.error_on_stderr?
+ tell_me(msg, :red, newline)
end
def debug(msg, newline = nil)
@@ -103,6 +105,11 @@ module Bundler
end
def tell_err(message, color = nil, newline = nil)
+ newline = message.to_s !~ /( |\t)\Z/ unless newline
+ message = word_wrap(message) if newline.is_a?(Hash) && newline[:wrap]
+
+ color = nil if color && !$stderr.tty?
+
buffer = @shell.send(:prepare_message, message, *color)
buffer << "\n" if newline && !message.to_s.end_with?("\n")
diff --git a/man/bundle-config.ronn b/man/bundle-config.ronn
index afae3e0888..b7ae07698c 100644
--- a/man/bundle-config.ronn
+++ b/man/bundle-config.ronn
@@ -222,6 +222,8 @@ learn more about their operation in [bundle install(1)][bundle-install].
* `gem.push_key` (`BUNDLE_GEM__PUSH_KEY`):
Sets the `--key` parameter for `gem push` when using the `rake release`
command with a private gemstash server.
+* `error_on_stderr` (`BUNDLE_ERROR_ON_STDERR`)
+ Print Bundler errors to stderr
In general, you should set these settings per-application by using the applicable
flag to the [bundle install(1)][bundle-install] or [bundle package(1)][bundle-package] command.
diff --git a/spec/bundler/ui/shell_spec.rb b/spec/bundler/ui/shell_spec.rb
new file mode 100644
index 0000000000..c5ccce534a
--- /dev/null
+++ b/spec/bundler/ui/shell_spec.rb
@@ -0,0 +1,49 @@
+# frozen_string_literal: true
+require "spec_helper"
+
+RSpec.describe Bundler::UI::Shell do
+ subject { described_class.new }
+
+ before { subject.level = "debug" }
+
+ describe "#info" do
+ before { subject.level = "info" }
+ it "prints to stdout" do
+ expect { subject.info("info") }.to output("info\n").to_stdout
+ end
+ end
+
+ describe "#confirm" do
+ before { subject.level = "confirm" }
+ it "prints to stdout" do
+ expect { subject.confirm("confirm") }.to output("confirm\n").to_stdout
+ end
+ end
+
+ describe "#warn" do
+ before { subject.level = "warn" }
+ it "prints to stdout" do
+ expect { subject.warn("warning") }.to output("warning\n").to_stdout
+ end
+ end
+
+ describe "#debug" do
+ it "prints to stdout" do
+ expect { subject.debug("debug") }.to output("debug\n").to_stdout
+ end
+ end
+
+ describe "#error" do
+ before { subject.level = "error" }
+ it "prints to stdout" do
+ expect { subject.error("error!!!") }.to output("error!!!\n").to_stdout
+ end
+
+ context "when stderr flag is enabled" do
+ before { Bundler.settings.temporary(:error_on_stderr => true) }
+ it "prints to stderr" do
+ expect { subject.error("error!!!") }.to output("error!!!\n").to_stderr
+ end
+ end
+ end
+end