зеркало из https://github.com/github/ruby.git
[rubygems/rubygems] Emit progress to stderr when `--print` is passed to `bundle lock`
`bundle lock --print --update` can take a long time to fetch sources and resolve the lock file. Before, `--print` caused output to be completely silenced, so nothing was printed at all until the resolved lock file is finally emitted to stdout. With this change, `--print` now prints progress to stderr. E.g.: ``` Fetching gem metadata from https://rubygems.org/......... Resolving dependencies... ``` This provides a better user experience, especially when `lock --print --update` takes several seconds or more. The lock file is still printed to stdout, so tools consuming the lock file on stdout will not be affected. https://github.com/rubygems/rubygems/commit/6719baa700
This commit is contained in:
Родитель
2066482684
Коммит
7c794c287e
|
@ -15,8 +15,8 @@ module Bundler
|
||||||
end
|
end
|
||||||
|
|
||||||
print = options[:print]
|
print = options[:print]
|
||||||
previous_ui_level = Bundler.ui.level
|
previous_output_stream = Bundler.ui.output_stream
|
||||||
Bundler.ui.level = "silent" if print
|
Bundler.ui.output_stream = :stderr if print
|
||||||
|
|
||||||
Bundler::Fetcher.disable_endpoint = options["full-index"]
|
Bundler::Fetcher.disable_endpoint = options["full-index"]
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ module Bundler
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Bundler.ui.level = previous_ui_level
|
Bundler.ui.output_stream = previous_output_stream
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,14 +6,17 @@ module Bundler
|
||||||
module UI
|
module UI
|
||||||
class Shell
|
class Shell
|
||||||
LEVELS = %w[silent error warn confirm info debug].freeze
|
LEVELS = %w[silent error warn confirm info debug].freeze
|
||||||
|
OUTPUT_STREAMS = [:stdout, :stderr].freeze
|
||||||
|
|
||||||
attr_writer :shell
|
attr_writer :shell
|
||||||
|
attr_reader :output_stream
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
Thor::Base.shell = options["no-color"] ? Thor::Shell::Basic : nil
|
Thor::Base.shell = options["no-color"] ? Thor::Shell::Basic : nil
|
||||||
@shell = Thor::Base.shell.new
|
@shell = Thor::Base.shell.new
|
||||||
@level = ENV["DEBUG"] ? "debug" : "info"
|
@level = ENV["DEBUG"] ? "debug" : "info"
|
||||||
@warning_history = []
|
@warning_history = []
|
||||||
|
@output_stream = :stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_color(string, *color)
|
def add_color(string, *color)
|
||||||
|
@ -101,6 +104,11 @@ module Bundler
|
||||||
index <= LEVELS.index(@level)
|
index <= LEVELS.index(@level)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def output_stream=(symbol)
|
||||||
|
raise ArgumentError unless OUTPUT_STREAMS.include?(symbol)
|
||||||
|
@output_stream = symbol
|
||||||
|
end
|
||||||
|
|
||||||
def trace(e, newline = nil, force = false)
|
def trace(e, newline = nil, force = false)
|
||||||
return unless debug? || force
|
return unless debug? || force
|
||||||
msg = "#{e.class}: #{e.message}\n#{e.backtrace.join("\n ")}"
|
msg = "#{e.class}: #{e.message}\n#{e.backtrace.join("\n ")}"
|
||||||
|
@ -119,6 +127,8 @@ module Bundler
|
||||||
|
|
||||||
# valimism
|
# valimism
|
||||||
def tell_me(msg, color = nil, newline = nil)
|
def tell_me(msg, color = nil, newline = nil)
|
||||||
|
return tell_err(msg, color, newline) if output_stream == :stderr
|
||||||
|
|
||||||
msg = word_wrap(msg) if newline.is_a?(Hash) && newline[:wrap]
|
msg = word_wrap(msg) if newline.is_a?(Hash) && newline[:wrap]
|
||||||
if newline.nil?
|
if newline.nil?
|
||||||
@shell.say(msg, color)
|
@shell.say(msg, color)
|
||||||
|
|
|
@ -53,6 +53,13 @@ module Bundler
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def output_stream=(_symbol)
|
||||||
|
end
|
||||||
|
|
||||||
|
def output_stream
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def ask(message)
|
def ask(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,13 @@ RSpec.describe Bundler::UI::Shell do
|
||||||
it "prints to stdout" do
|
it "prints to stdout" do
|
||||||
expect { subject.info("info") }.to output("info\n").to_stdout
|
expect { subject.info("info") }.to output("info\n").to_stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when output_stream is :stderr" do
|
||||||
|
before { subject.output_stream = :stderr }
|
||||||
|
it "prints to stderr" do
|
||||||
|
expect { subject.info("info") }.to output("info\n").to_stderr
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#confirm" do
|
describe "#confirm" do
|
||||||
|
@ -17,6 +24,13 @@ RSpec.describe Bundler::UI::Shell do
|
||||||
it "prints to stdout" do
|
it "prints to stdout" do
|
||||||
expect { subject.confirm("confirm") }.to output("confirm\n").to_stdout
|
expect { subject.confirm("confirm") }.to output("confirm\n").to_stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when output_stream is :stderr" do
|
||||||
|
before { subject.output_stream = :stderr }
|
||||||
|
it "prints to stderr" do
|
||||||
|
expect { subject.confirm("confirm") }.to output("confirm\n").to_stderr
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#warn" do
|
describe "#warn" do
|
||||||
|
@ -33,6 +47,13 @@ RSpec.describe Bundler::UI::Shell do
|
||||||
it "prints to stdout" do
|
it "prints to stdout" do
|
||||||
expect { subject.debug("debug") }.to output("debug\n").to_stdout
|
expect { subject.debug("debug") }.to output("debug\n").to_stdout
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when output_stream is :stderr" do
|
||||||
|
before { subject.output_stream = :stderr }
|
||||||
|
it "prints to stderr" do
|
||||||
|
expect { subject.debug("debug") }.to output("debug\n").to_stderr
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#error" do
|
describe "#error" do
|
||||||
|
|
|
@ -202,6 +202,25 @@ RSpec.describe "bundle lock" do
|
||||||
expect(read_lockfile).to eq(expected_lockfile)
|
expect(read_lockfile).to eq(expected_lockfile)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "prints an updated lockfile when there is an outdated lockfile using --print --update" do
|
||||||
|
lockfile outdated_lockfile
|
||||||
|
|
||||||
|
bundle "lock --print --update"
|
||||||
|
|
||||||
|
expect(out).to eq(expected_lockfile.rstrip)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "emits info messages to stderr when updating an outdated lockfile using --print --update" do
|
||||||
|
lockfile outdated_lockfile
|
||||||
|
|
||||||
|
bundle "lock --print --update"
|
||||||
|
|
||||||
|
expect(err).to eq(<<~STDERR.rstrip)
|
||||||
|
Fetching gem metadata from https://gem.repo4/...
|
||||||
|
Resolving dependencies...
|
||||||
|
STDERR
|
||||||
|
end
|
||||||
|
|
||||||
it "writes a lockfile when there is an outdated lockfile and bundle is frozen" do
|
it "writes a lockfile when there is an outdated lockfile and bundle is frozen" do
|
||||||
lockfile outdated_lockfile
|
lockfile outdated_lockfile
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче