From 39d7cd8997a97198d67a26ce2f383f97d3d319b4 Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 3 Apr 2020 15:51:35 -0400 Subject: [PATCH] Wrap all progress type outputs with rewriting to enable --no-tty --- lib/vagrant/ui.rb | 3 +++ lib/vagrant/util/curl_helper.rb | 6 ++++-- plugins/providers/hyperv/action/export.rb | 6 ++++-- plugins/providers/virtualbox/action/export.rb | 6 ++++-- plugins/providers/virtualbox/action/import.rb | 12 ++++++++---- .../virtualbox/action/prepare_clone_snapshot.rb | 6 ++++-- .../providers/virtualbox/action/snapshot_delete.rb | 6 ++++-- .../providers/virtualbox/action/snapshot_restore.rb | 6 ++++-- test/unit/vagrant/util/downloader_test.rb | 1 + 9 files changed, 36 insertions(+), 16 deletions(-) diff --git a/lib/vagrant/ui.rb b/lib/vagrant/ui.rb index aa2acf374..a521fd105 100644 --- a/lib/vagrant/ui.rb +++ b/lib/vagrant/ui.rb @@ -76,6 +76,9 @@ module Vagrant @logger.info("Machine: #{type} #{data.inspect}") end + # Yields self (UI) + # Provides a way for selectively displaying or not displaying + # updating content like download progress. def rewriting yield self end diff --git a/lib/vagrant/util/curl_helper.rb b/lib/vagrant/util/curl_helper.rb index 67b772b54..8c3d205d9 100644 --- a/lib/vagrant/util/curl_helper.rb +++ b/lib/vagrant/util/curl_helper.rb @@ -37,8 +37,10 @@ module Vagrant source_host = source_uri.host.to_s.split(".", 2).last location_host = location_uri.host.to_s.split(".", 2).last if !redirect_notify && location_host != source_host && !SILENCED_HOSTS.include?(location_host) - ui.clear_line - ui.detail "Download redirected to host: #{location_uri.host}" + ui.rewriting do |ui| + ui.clear_line + ui.detail "Download redirected to host: #{location_uri.host}" + end end redirect_notify = true end diff --git a/plugins/providers/hyperv/action/export.rb b/plugins/providers/hyperv/action/export.rb index 28b5ab4be..34a540409 100644 --- a/plugins/providers/hyperv/action/export.rb +++ b/plugins/providers/hyperv/action/export.rb @@ -25,8 +25,10 @@ module VagrantPlugins @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting") export_tmp_dir = Vagrant::Util::Platform.wsl_to_windows_path(@env["export.temp_dir"]) @env[:machine].provider.driver.export(export_tmp_dir) do |progress| - @env[:ui].clear_line - @env[:ui].report_progress(progress.percent, 100, false) + @env[:ui].rewriting do |ui| + ui.clear_line + ui.report_progress(progress.percent, 100, false) + end end # Clear the line a final time so the next data can appear diff --git a/plugins/providers/virtualbox/action/export.rb b/plugins/providers/virtualbox/action/export.rb index f9132c3c4..51c1621f3 100644 --- a/plugins/providers/virtualbox/action/export.rb +++ b/plugins/providers/virtualbox/action/export.rb @@ -23,8 +23,10 @@ module VagrantPlugins def export @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting") @env[:machine].provider.driver.export(ovf_path) do |progress| - @env[:ui].clear_line - @env[:ui].report_progress(progress.percent, 100, false) + @env[:ui].rewriting do |ui| + ui.clear_line + ui.report_progress(progress.percent, 100, false) + end end # Clear the line a final time so the next data can appear diff --git a/plugins/providers/virtualbox/action/import.rb b/plugins/providers/virtualbox/action/import.rb index fb540f50a..704814b61 100644 --- a/plugins/providers/virtualbox/action/import.rb +++ b/plugins/providers/virtualbox/action/import.rb @@ -19,8 +19,10 @@ module VagrantPlugins env[:ui].info I18n.t("vagrant.actions.vm.clone.creating") env[:machine].id = env[:machine].provider.driver.clonevm( env[:clone_id], env[:clone_snapshot]) do |progress| - env[:ui].clear_line - env[:ui].report_progress(progress, 100, false) + env[:ui].rewriting do |ui| + ui.clear_line + ui.report_progress(progress, 100, false) + end end # Clear the line one last time since the progress meter doesn't @@ -51,8 +53,10 @@ module VagrantPlugins # Import the virtual machine ovf_file = env[:machine].box.directory.join("box.ovf").to_s id = env[:machine].provider.driver.import(ovf_file) do |progress| - env[:ui].clear_line - env[:ui].report_progress(progress, 100, false) + env[:ui].rewriting do |ui| + ui.clear_line + ui.report_progress(progress, 100, false) + end end # Set the machine ID diff --git a/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb b/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb index 08ce16a6d..653e61a91 100644 --- a/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb +++ b/plugins/providers/virtualbox/action/prepare_clone_snapshot.rb @@ -55,8 +55,10 @@ module VagrantPlugins @logger.info("Creating base snapshot for master VM.") env[:machine].provider.driver.create_snapshot( env[:clone_id], name) do |progress| - env[:ui].clear_line - env[:ui].report_progress(progress, 100, false) + env[:ui].rewriting do |ui| + ui.clear_line + ui.report_progress(progress, 100, false) + end end end end diff --git a/plugins/providers/virtualbox/action/snapshot_delete.rb b/plugins/providers/virtualbox/action/snapshot_delete.rb index 1d8cecc73..74fac9440 100644 --- a/plugins/providers/virtualbox/action/snapshot_delete.rb +++ b/plugins/providers/virtualbox/action/snapshot_delete.rb @@ -12,8 +12,10 @@ module VagrantPlugins name: env[:snapshot_name])) env[:machine].provider.driver.delete_snapshot( env[:machine].id, env[:snapshot_name]) do |progress| - env[:ui].clear_line - env[:ui].report_progress(progress, 100, false) + env[:ui].rewriting do |ui| + ui.clear_line + ui.report_progress(progress, 100, false) + end end # Clear the line one last time since the progress meter doesn't disappear diff --git a/plugins/providers/virtualbox/action/snapshot_restore.rb b/plugins/providers/virtualbox/action/snapshot_restore.rb index f655471c1..922d51d84 100644 --- a/plugins/providers/virtualbox/action/snapshot_restore.rb +++ b/plugins/providers/virtualbox/action/snapshot_restore.rb @@ -12,8 +12,10 @@ module VagrantPlugins name: env[:snapshot_name])) env[:machine].provider.driver.restore_snapshot( env[:machine].id, env[:snapshot_name]) do |progress| - env[:ui].clear_line - env[:ui].report_progress(progress, 100, false) + env[:ui].rewriting do |ui| + ui.clear_line + ui.report_progress(progress, 100, false) + end end # Clear the line one last time since the progress meter doesn't disappear diff --git a/test/unit/vagrant/util/downloader_test.rb b/test/unit/vagrant/util/downloader_test.rb index 0aa29f5fd..973510259 100644 --- a/test/unit/vagrant/util/downloader_test.rb +++ b/test/unit/vagrant/util/downloader_test.rb @@ -38,6 +38,7 @@ describe Vagrant::Util::Downloader do before do allow(ui).to receive(:clear_line) allow(ui).to receive(:detail) + allow(ui).to receive(:rewriting).and_yield(ui) end after do