From a601d8429dd351f47f128685b6a5eb8472459fa7 Mon Sep 17 00:00:00 2001 From: Red Wizard <138079934+The-RedWizard@users.noreply.github.com> Date: Sun, 30 Mar 2025 09:11:04 -0400 Subject: [PATCH] added silent install option for winget (#1089) * added silent install option for winget * corrected formatting issues. * Update src/steps/os/windows.rs Remove code duplication. Co-authored-by: SteveLauC --------- Co-authored-by: SteveLauC --- config.example.toml | 4 ++++ src/config.rs | 9 +++++++++ src/steps/os/windows.rs | 10 ++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config.example.toml b/config.example.toml index 276f9e57..7c0db353 100644 --- a/config.example.toml +++ b/config.example.toml @@ -219,6 +219,10 @@ # wsl_update_use_web_download = true +# The default for winget_install_silently is true, +# this example turns off silent install. +# winget_install_silently = false + # Causes Topgrade to rename itself during the run to allow package managers # to upgrade it. Use this only if you installed Topgrade by using a package # manager such as Scoop or Cargo diff --git a/src/config.rs b/src/config.rs index e4a29063..7b2dc4b5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -225,6 +225,7 @@ pub struct Windows { open_remotes_in_new_terminal: Option, wsl_update_pre_release: Option, wsl_update_use_web_download: Option, + winget_silent_install: Option, } #[derive(Deserialize, Default, Debug, Merge)] @@ -1550,6 +1551,14 @@ impl Config { .unwrap_or(false) } + pub fn winget_silent_install(&self) -> bool { + self.config_file + .windows + .as_ref() + .and_then(|windows| windows.winget_silent_install) + .unwrap_or(true) + } + pub fn sudo_command(&self) -> Option { self.config_file.misc.as_ref().and_then(|misc| misc.sudo_command) } diff --git a/src/steps/os/windows.rs b/src/steps/os/windows.rs index 575ec7ca..260142d8 100644 --- a/src/steps/os/windows.rs +++ b/src/steps/os/windows.rs @@ -42,10 +42,12 @@ pub fn run_winget(ctx: &ExecutionContext) -> Result<()> { print_separator("winget"); - ctx.run_type() - .execute(winget) - .args(["upgrade", "--all"]) - .status_checked() + let mut args = vec!["upgrade", "--all"]; + if ctx.config().winget_silent_install() { + args.push("--silent"); + } + + ctx.run_type().execute(winget).args(args).status_checked() } pub fn run_scoop(ctx: &ExecutionContext) -> Result<()> {