Support yay arguments in config file (Closes #220) (#233)

This commit is contained in:
Idan Katz
2019-10-03 08:12:43 +03:00
committed by Roey Darwish Dror
parent 623929cb64
commit 11694247c1
4 changed files with 28 additions and 5 deletions

View File

@@ -16,6 +16,9 @@
# Arguments to pass Git when pulling Repositories # Arguments to pass Git when pulling Repositories
#git_arguments = "--rebase --autostash" #git_arguments = "--rebase --autostash"
# Arguments to pass yay when updating packages
#yay_arguments = "--nodevel"
# Do not set the terminal title # Do not set the terminal title
#set_title = false #set_title = false
# Commands to run before anything # Commands to run before anything

View File

@@ -61,6 +61,7 @@ pub struct ConfigFile {
git_arguments: Option<String>, git_arguments: Option<String>,
set_title: Option<bool>, set_title: Option<bool>,
assume_yes: Option<bool>, assume_yes: Option<bool>,
yay_arguments: Option<String>,
} }
impl ConfigFile { impl ConfigFile {
@@ -286,4 +287,13 @@ impl Config {
pub fn yes(&self) -> bool { pub fn yes(&self) -> bool {
self.config_file.assume_yes.unwrap_or(self.opt.yes) self.config_file.assume_yes.unwrap_or(self.opt.yes)
} }
/// Extra yay arguments
#[cfg(target_os = "linux")]
pub fn yay_arguments(&self) -> &str {
match &self.config_file.yay_arguments {
Some(args) => args.as_str(),
None => "--devel",
}
}
} }

View File

@@ -158,7 +158,7 @@ fn run() -> Result<(), Error> {
execute( execute(
&mut report, &mut report,
"System update", "System update",
|| distribution.upgrade(&sudo, config.cleanup(), run_type, config.yes()), || distribution.upgrade(&sudo, run_type, &config),
config.no_retry(), config.no_retry(),
)?; )?;
} }

View File

@@ -1,3 +1,4 @@
use crate::config::Config;
use crate::error::{Error, ErrorKind}; use crate::error::{Error, ErrorKind};
use crate::executor::RunType; use crate::executor::RunType;
use crate::terminal::{print_separator, print_warning}; use crate::terminal::{print_separator, print_warning};
@@ -75,11 +76,14 @@ impl Distribution {
} }
#[must_use] #[must_use]
pub fn upgrade(self, sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType, yes: bool) -> Result<(), Error> { pub fn upgrade(self, sudo: &Option<PathBuf>, run_type: RunType, config: &Config) -> Result<(), Error> {
print_separator("System update"); print_separator("System update");
let yes = config.yes();
let cleanup = config.cleanup();
match self { match self {
Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type, yes), Distribution::Arch => upgrade_arch_linux(&sudo, cleanup, run_type, yes, &config.yay_arguments()),
Distribution::CentOS | Distribution::Fedora => upgrade_redhat(&sudo, run_type, yes), Distribution::CentOS | Distribution::Fedora => upgrade_redhat(&sudo, run_type, yes),
Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type, yes), Distribution::Debian => upgrade_debian(&sudo, cleanup, run_type, yes),
Distribution::Gentoo => upgrade_gentoo(&sudo, run_type), Distribution::Gentoo => upgrade_gentoo(&sudo, run_type),
@@ -118,7 +122,13 @@ pub fn show_pacnew() {
} }
} }
fn upgrade_arch_linux(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType, yes: bool) -> Result<(), Error> { fn upgrade_arch_linux(
sudo: &Option<PathBuf>,
cleanup: bool,
run_type: RunType,
yes: bool,
yay_arguments: &str,
) -> Result<(), Error> {
let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman")); let pacman = which("powerpill").unwrap_or_else(|| PathBuf::from("/usr/bin/pacman"));
let path = { let path = {
@@ -135,7 +145,7 @@ fn upgrade_arch_linux(sudo: &Option<PathBuf>, cleanup: bool, run_type: RunType,
.arg("--pacman") .arg("--pacman")
.arg(pacman) .arg(pacman)
.arg("-Syu") .arg("-Syu")
.arg("--devel") .args(yay_arguments.split_whitespace())
.env("PATH", path); .env("PATH", path);
if yes { if yes {