core: make box add UI much icer
This commit is contained in:
parent
c1d5c8f33c
commit
b71cde6b99
|
@ -59,6 +59,8 @@ module Vagrant
|
||||||
url = env[:box_url]
|
url = env[:box_url]
|
||||||
version = env[:box_version]
|
version = env[:box_version]
|
||||||
|
|
||||||
|
env[:ui].output(I18n.t(
|
||||||
|
"vagrant.box_loading_metadata", name: url))
|
||||||
metadata = nil
|
metadata = nil
|
||||||
begin
|
begin
|
||||||
metadata_path = download(url, env, ui: false)
|
metadata_path = download(url, env, ui: false)
|
||||||
|
|
|
@ -209,7 +209,10 @@ module Vagrant
|
||||||
class_eval <<-CODE
|
class_eval <<-CODE
|
||||||
def #{method}(message, *args, **opts)
|
def #{method}(message, *args, **opts)
|
||||||
super(message)
|
super(message)
|
||||||
opts[:bold] = #{method.inspect} != :detail if !opts.has_key?(:bold)
|
if !opts.has_key?(:bold)
|
||||||
|
opts[:bold] = #{method.inspect} != :detail && \
|
||||||
|
#{method.inspect} != :ask
|
||||||
|
end
|
||||||
@ui.#{method}(format_message(#{method.inspect}, message, **opts), *args, **opts)
|
@ui.#{method}(format_message(#{method.inspect}, message, **opts), *args, **opts)
|
||||||
end
|
end
|
||||||
CODE
|
CODE
|
||||||
|
@ -241,7 +244,8 @@ module Vagrant
|
||||||
prefix = ""
|
prefix = ""
|
||||||
if !opts.has_key?(:prefix) || opts[:prefix]
|
if !opts.has_key?(:prefix) || opts[:prefix]
|
||||||
prefix = OUTPUT_PREFIX
|
prefix = OUTPUT_PREFIX
|
||||||
prefix = " " * OUTPUT_PREFIX.length if type == :detail
|
prefix = " " * OUTPUT_PREFIX.length if \
|
||||||
|
type == :detail || type == :ask
|
||||||
end
|
end
|
||||||
|
|
||||||
# Fast-path if there is no prefix
|
# Fast-path if there is no prefix
|
||||||
|
@ -281,16 +285,17 @@ module Vagrant
|
||||||
opts[:color] = :green if type == :success
|
opts[:color] = :green if type == :success
|
||||||
opts[:color] = :yellow if type == :warn
|
opts[:color] = :yellow if type == :warn
|
||||||
|
|
||||||
# If there is no color specified, exit early
|
|
||||||
return message if !opts.has_key?(:color)
|
|
||||||
|
|
||||||
# If it is a detail, it is not bold. Every other message type
|
# If it is a detail, it is not bold. Every other message type
|
||||||
# is bolded.
|
# is bolded.
|
||||||
bold = !!opts[:bold]
|
bold = !!opts[:bold]
|
||||||
color = COLORS[opts[:color]]
|
colorseq = "#{bold ? 1 : 0 }"
|
||||||
|
if opts[:color]
|
||||||
|
color = COLORS[opts[:color]]
|
||||||
|
colorseq += ";#{color}"
|
||||||
|
end
|
||||||
|
|
||||||
# Color the message and make sure to reset the color at the end
|
# Color the message and make sure to reset the color at the end
|
||||||
"\033[#{bold ? 1 : 0};#{color}m#{message}\033[0m"
|
"\033[#{colorseq}m#{message}\033[0m"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -92,7 +92,7 @@ module Vagrant
|
||||||
|
|
||||||
output = "Progress: #{columns[0]}% (Rate: #{columns[11]}/s, Estimated time remaining: #{columns[10]})"
|
output = "Progress: #{columns[0]}% (Rate: #{columns[11]}/s, Estimated time remaining: #{columns[10]})"
|
||||||
@ui.clear_line
|
@ui.clear_line
|
||||||
@ui.info(output, :new_line => false)
|
@ui.detail(output, :new_line => false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -111,7 +111,7 @@ module Vagrant
|
||||||
|
|
||||||
# Windows doesn't clear properly for some reason, so we just
|
# Windows doesn't clear properly for some reason, so we just
|
||||||
# output one more newline.
|
# output one more newline.
|
||||||
@ui.info("") if Platform.windows?
|
@ui.detail("") if Platform.windows?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ module VagrantPlugins
|
||||||
box_download_ca_cert: options[:ca_cert],
|
box_download_ca_cert: options[:ca_cert],
|
||||||
box_download_client_cert: options[:client_cert],
|
box_download_client_cert: options[:client_cert],
|
||||||
box_download_insecure: options[:insecure],
|
box_download_insecure: options[:insecure],
|
||||||
|
ui: Vagrant::UI::Prefixed.new(@env.ui, "box"),
|
||||||
})
|
})
|
||||||
|
|
||||||
# Success, exit status 0
|
# Success, exit status 0
|
||||||
|
|
|
@ -18,6 +18,8 @@ en:
|
||||||
Adding box '%{name}' (v%{version}) for '%{provider}' provider...
|
Adding box '%{name}' (v%{version}) for '%{provider}' provider...
|
||||||
box_added: |-
|
box_added: |-
|
||||||
Successfully added box '%{name}' for '%{provider}'!
|
Successfully added box '%{name}' for '%{provider}'!
|
||||||
|
box_loading_metadata: |-
|
||||||
|
Loading metadata for box '%{name}'
|
||||||
cfengine_bootstrapping: |-
|
cfengine_bootstrapping: |-
|
||||||
Bootstrapping CFEngine with policy server: %{policy_server}...
|
Bootstrapping CFEngine with policy server: %{policy_server}...
|
||||||
cfengine_bootstrapping_policy_hub: |-
|
cfengine_bootstrapping_policy_hub: |-
|
||||||
|
|
|
@ -65,7 +65,7 @@ describe Vagrant::UI::Colored do
|
||||||
|
|
||||||
describe "#detail" do
|
describe "#detail" do
|
||||||
it "colors output nothing by default" do
|
it "colors output nothing by default" do
|
||||||
subject.should_receive(:safe_puts).with("foo", anything)
|
subject.should_receive(:safe_puts).with("\033[0mfoo\033[0m", anything)
|
||||||
subject.detail("foo")
|
subject.detail("foo")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -91,11 +91,16 @@ describe Vagrant::UI::Colored do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#output" do
|
describe "#output" do
|
||||||
it "colors output nothing by default" do
|
it "colors output nothing by default, no bold" do
|
||||||
subject.should_receive(:safe_puts).with("foo", anything)
|
subject.should_receive(:safe_puts).with("\033[0mfoo\033[0m", anything)
|
||||||
subject.output("foo")
|
subject.output("foo")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "bolds output without color if specified" do
|
||||||
|
subject.should_receive(:safe_puts).with("\033[1mfoo\033[0m", anything)
|
||||||
|
subject.output("foo", bold: true)
|
||||||
|
end
|
||||||
|
|
||||||
it "colors output to color specified in global opts" do
|
it "colors output to color specified in global opts" do
|
||||||
subject.opts[:color] = :red
|
subject.opts[:color] = :red
|
||||||
|
|
||||||
|
@ -232,6 +237,13 @@ describe Vagrant::UI::Prefixed do
|
||||||
|
|
||||||
subject { described_class.new(ui, prefix) }
|
subject { described_class.new(ui, prefix) }
|
||||||
|
|
||||||
|
describe "#ask" do
|
||||||
|
it "does not request bolding" do
|
||||||
|
ui.should_receive(:ask).with(" #{prefix}: foo", bold: false)
|
||||||
|
subject.ask("foo")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#detail" do
|
describe "#detail" do
|
||||||
it "prefixes with spaces and the message" do
|
it "prefixes with spaces and the message" do
|
||||||
ui.should_receive(:safe_puts).with(" #{prefix}: foo", anything)
|
ui.should_receive(:safe_puts).with(" #{prefix}: foo", anything)
|
||||||
|
|
Loading…
Reference in New Issue