diff --git a/config.example.toml b/config.example.toml index 28474b96..da85953c 100644 --- a/config.example.toml +++ b/config.example.toml @@ -31,9 +31,6 @@ # Arguments to pass tmux when pulling Repositories #tmux_arguments = "-S /var/tmux.sock" -# Arguments to pass yay when updating packages -#yay_arguments = "--nodevel" - # Manually select Windows updates # accept_all_windows_updates = false @@ -56,3 +53,7 @@ #[brew] #greedy_cask = true + +#[linux] +# Arguments to pass yay when updating packages +#yay_arguments = "--nodevel" diff --git a/src/config.rs b/src/config.rs index 2dc7b022..96e1b9b1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,4 @@ use super::utils::editor; -#[cfg(target_os = "macos")] use crate::terminal::print_warning; use anyhow::Result; use directories::BaseDirs; @@ -56,6 +55,12 @@ pub struct Brew { greedy_cask: Option, } +#[derive(Deserialize, Default, Debug)] +pub struct Linux { + yay_arguments: Option, + dnf_arguments: Option, +} + #[derive(Deserialize, Default, Debug)] pub struct Composer { self_update: Option, @@ -85,6 +90,7 @@ pub struct ConfigFile { only: Option>, composer: Option, brew: Option, + linux: Option, } impl ConfigFile { @@ -402,12 +408,23 @@ impl Config { } /// Extra yay arguments - #[cfg(target_os = "linux")] + #[allow(dead_code)] pub fn yay_arguments(&self) -> &str { - match &self.config_file.yay_arguments { - Some(args) => args.as_str(), - None => "--devel", - } + &self.config_file.yay_arguments.as_deref().map(|p| { + print_warning("Putting --yay-arguments in the top section is deprecated and will be removed in the future. Please move it to the [linux] section"); + p + }) + .or_else(|| self.config_file.linux.as_ref().and_then(|s| s.yay_arguments.as_deref())) + .unwrap_or("--devel") + } + + /// Extra yay arguments + #[allow(dead_code)] + pub fn dnf_arguments(&self) -> Option<&str> { + self.config_file + .linux + .as_ref() + .and_then(|linux| linux.dnf_arguments.as_deref()) } pub fn use_predefined_git_repos(&self) -> bool { diff --git a/src/main.rs b/src/main.rs index b3fb06c0..d94fe7b2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,7 +119,7 @@ fn run() -> Result<()> { if config.should_run(Step::System) { match &distribution { Ok(distribution) => { - runner.execute("System update", || distribution.upgrade(&sudo, run_type, &config))?; + runner.execute("System update", || distribution.upgrade(&ctx))?; } Err(e) => { println!("Error detecting current distribution: {}", e); diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index d03cb232..69fb3c2f 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -1,5 +1,5 @@ -use crate::config::Config; use crate::error::{SkipStep, TopgradeError}; +use crate::execution_context::ExecutionContext; use crate::executor::{ExecutorExitStatus, RunType}; use crate::terminal::{print_separator, print_warning}; use crate::utils::{require, require_option, which, PathExt}; @@ -79,15 +79,16 @@ impl Distribution { Err(TopgradeError::UnknownLinuxDistribution.into()) } - pub fn upgrade(self, sudo: &Option, run_type: RunType, config: &Config) -> Result<()> { + pub fn upgrade(self, ctx: &ExecutionContext) -> Result<()> { print_separator("System update"); - - let yes = config.yes(); - let cleanup = config.cleanup(); + let sudo = ctx.sudo(); + let run_type = ctx.run_type(); + let yes = ctx.config().yes(); + let cleanup = ctx.config().cleanup(); match self { - Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type, yes, &config.yay_arguments()), - Distribution::CentOS | Distribution::Fedora => upgrade_redhat(&sudo, run_type, yes), + Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type, yes, &ctx.config().yay_arguments()), + Distribution::CentOS | Distribution::Fedora => upgrade_redhat(ctx), Distribution::ClearLinux => upgrade_clearlinux(&sudo, run_type), Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type, yes), Distribution::Gentoo => upgrade_gentoo(&sudo, run_type), @@ -196,9 +197,9 @@ fn upgrade_arch_linux( Ok(()) } -fn upgrade_redhat(sudo: &Option, run_type: RunType, yes: bool) -> Result<()> { - if let Some(sudo) = &sudo { - let mut command = run_type.execute(&sudo); +fn upgrade_redhat(ctx: &ExecutionContext) -> Result<()> { + if let Some(sudo) = &ctx.sudo() { + let mut command = ctx.run_type().execute(&sudo); command .arg(Path::new("/usr/bin/dnf").if_exists().unwrap_or_else(|| { Path::new("/usr/bin/yum") @@ -206,7 +207,12 @@ fn upgrade_redhat(sudo: &Option, run_type: RunType, yes: bool) -> Resul .unwrap_or_else(|| Path::new("/usr/bin/rpm-ostree")) })) .arg("upgrade"); - if yes { + + if let Some(args) = ctx.config().dnf_arguments() { + command.args(args.split_whitespace()); + } + + if ctx.config().yes() { command.arg("-y"); }