Skip to content

Commit

Permalink
fix(aura): propagate --noconfirm to all prompts
Browse files Browse the repository at this point in the history
See #882
  • Loading branch information
fosskers committed Aug 7, 2024
1 parent 002c17b commit e0d2137
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- Zsh completions of `-S`.
- `check`: confirm that `dot` is on the system. If missing, it belongs to the `graphviz` package.
- `--noconfirm` now affects all prompts.

## 4.0.1

Expand Down
4 changes: 2 additions & 2 deletions rust/aura-pm/src/command/aur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ where
// Prompt if the user specified packages that are marked "ignored".
if env.aur.ignores.contains(*p) {
let pkg = p.bold().cyan().to_string();
proceed!(fll, "A-install-ignored", file = pkg).is_some()
proceed!(fll, env, "A-install-ignored", file = pkg).is_some()
} else {
true
}
Expand Down Expand Up @@ -503,7 +503,7 @@ fn install_work(

if env.aur.noconfirm.not() {
// Proceed if the user accepts.
proceed!(fll, "proceed").ok_or(Error::Cancelled)?;
proceed!(fll, env, "proceed").ok_or(Error::Cancelled)?;
}

if matches!(mode, Mode::Upgrade) && env.backups.automatic {
Expand Down
30 changes: 17 additions & 13 deletions rust/aura-pm/src/command/aur/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ where

let to_install = pkg_clones
.map(|path| build_one(fll, caches, env, alpm, editor, requested, path))
.map(|r| build_check(fll, is_single, r))
.map(|r| build_check(fll, env, is_single, r))
.collect::<Result<Vec<Option<Built>>, Error>>()?
.into_iter()
.flatten()
Expand Down Expand Up @@ -188,15 +188,15 @@ fn build_one(
.map_err(Error::CopyBuildFiles)?;

if env.aur.diff {
show_diffs(fll, &env.aur.hashes, &clone, base)?;
show_diffs(fll, env, &clone, base)?;
}

if env.aur.hotedit {
overwrite_build_files(fll, editor, &build_dir, base)?;
overwrite_build_files(fll, env, editor, &build_dir, base)?;
}

if env.aur.shellcheck {
shellcheck(fll, &build_dir)?;
shellcheck(fll, env, &build_dir)?;
}

let tarballs = {
Expand Down Expand Up @@ -297,19 +297,21 @@ fn all_install_files(clone: &Path) -> Vec<PathBuf> {

fn show_diffs(
fll: &FluentLanguageLoader,
hashes: &Path,
env: &Env,
clone: &Path,
pkgbase: &str,
) -> Result<(), Error> {
let hashes = env.aur.hashes.as_path();

// Silently skip over any hashes that couldn't be read. This is mostly
// likely due to the package being installed for the first time, thus having
// no history to compare to.
match hash_of_last_install(hashes, pkgbase) {
Err(e) => warn!("Couldn't read latest hash of {}: {}", pkgbase, e),
Ok(hash) => {
if proceed!(fll, "A-build-diff").is_some() {
if proceed!(fll, env, "A-build-diff").is_some() {
aura_core::git::diff(clone, &hash).map_err(Error::GitDiff)?;
proceed!(fll, "proceed").ok_or(Error::Cancelled)?;
proceed!(fll, env, "proceed").ok_or(Error::Cancelled)?;
}
}
}
Expand All @@ -324,7 +326,7 @@ fn hash_of_last_install(hashes: &Path, pkgbase: &str) -> Result<String, std::io:
std::fs::read_to_string(path).map(|s| s.trim().to_string())
}

fn shellcheck(fll: &FluentLanguageLoader, build_d: &Path) -> Result<(), Error> {
fn shellcheck(fll: &FluentLanguageLoader, env: &Env, build_d: &Path) -> Result<(), Error> {
let status = Command::new("shellcheck")
.current_dir(build_d)
.arg("--severity=error")
Expand All @@ -334,12 +336,12 @@ fn shellcheck(fll: &FluentLanguageLoader, build_d: &Path) -> Result<(), Error> {

match status {
Ok(s) if s.success().not() => {
proceed!(fll, "proceed").ok_or(Error::Cancelled)?;
proceed!(fll, env, "proceed").ok_or(Error::Cancelled)?;
}
Err(e) => {
let msg = e.to_string().yellow();
aln!(msg);
proceed!(fll, "proceed").ok_or(Error::Cancelled)?;
proceed!(fll, env, "proceed").ok_or(Error::Cancelled)?;
}
Ok(_) => {}
}
Expand All @@ -349,12 +351,13 @@ fn shellcheck(fll: &FluentLanguageLoader, build_d: &Path) -> Result<(), Error> {

fn overwrite_build_files(
fll: &FluentLanguageLoader,
env: &Env,
editor: &str,
build_d: &Path,
pkgbase: &str,
) -> Result<(), Error> {
// --- Edit the PKGBUILD in-place --- //
if proceed!(fll, "A-build-hotedit-pkgbuild").is_some() {
if proceed!(fll, env, "A-build-hotedit-pkgbuild").is_some() {
let pkgbuild = build_d.join("PKGBUILD");
edit(editor, pkgbuild)?;
}
Expand All @@ -366,7 +369,7 @@ fn overwrite_build_files(
install
};

if install.is_file() && proceed!(fll, "A-build-hotedit-install").is_some() {
if install.is_file() && proceed!(fll, env, "A-build-hotedit-install").is_some() {
edit(editor, install)?;
}

Expand Down Expand Up @@ -563,6 +566,7 @@ fn move_tarball(source: &Path, target: &Path) -> Result<(), Error> {

fn build_check(
fll: &FluentLanguageLoader,
env: &Env,
is_single: bool,
r: Result<Built, Error>,
) -> Result<Option<Built>, Error> {
Expand All @@ -572,7 +576,7 @@ fn build_check(
red!(fll, "A-build-fail");
eprintln!("\n {}\n", e.localise(fll));

if is_single || proceed!(fll, "A-build-continue").is_none() {
if is_single || proceed!(fll, env, "A-build-continue").is_none() {
Err(Error::Cancelled)
} else {
Ok(None)
Expand Down
6 changes: 3 additions & 3 deletions rust/aura-pm/src/command/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ pub(crate) fn clean(env: &Env, fll: &FluentLanguageLoader, keep: usize) -> Resul
yellow!(fll, "C-c-keep", pkgs = keep);

// Proceed if the user accepts.
proceed!(fll, "proceed").ok_or(Error::Cancelled)?;
proceed!(fll, env, "proceed").ok_or(Error::Cancelled)?;

let elevation = env.sudo();

Expand Down Expand Up @@ -287,7 +287,7 @@ pub(crate) fn clean_not_saved(fll: &FluentLanguageLoader, env: &Env) -> Result<(
aura!(fll, "C-size", size = human);

// Proceed if the user accepts.
proceed!(fll, "proceed").ok_or(Error::Cancelled)?;
proceed!(fll, env, "proceed").ok_or(Error::Cancelled)?;

let tarballs = aura_core::cache::package_paths(&caches);

Expand Down Expand Up @@ -380,7 +380,7 @@ pub(crate) fn backup(fll: &FluentLanguageLoader, env: &Env, target: &Path) -> Re
}

// Proceed if the user accepts.
proceed!(fll, "proceed").ok_or(Error::Cancelled)?;
proceed!(fll, env, "proceed").ok_or(Error::Cancelled)?;

copy(&sources, &full, cache_size.files)
}
Expand Down
12 changes: 5 additions & 7 deletions rust/aura-pm/src/command/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,11 @@ pub(crate) fn save(fll: &FluentLanguageLoader, alpm: &Alpm, snapshots: &Path) ->
}

/// Remove all saveds snapshots that don't have tarballs in the cache.
pub(crate) fn clean(
fll: &FluentLanguageLoader,
caches: &[&Path],
snapshots: &Path,
) -> Result<(), Error> {
proceed!(fll, "B-clean").ok_or(Error::Cancelled)?;
let vers = aura_core::cache::all_versions(caches);
pub(crate) fn clean(fll: &FluentLanguageLoader, env: &Env) -> Result<(), Error> {
proceed!(fll, env, "B-clean").ok_or(Error::Cancelled)?;
let caches = env.caches();
let snapshots = env.backups.snapshots.as_path();
let vers = aura_core::cache::all_versions(&caches);

for (path, snapshot) in aura_core::snapshot::snapshots_with_paths(snapshots) {
if snapshot.pinned.not() && snapshot.usable(&vers).not() {
Expand Down
40 changes: 24 additions & 16 deletions rust/aura-pm/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,30 @@ macro_rules! executable {
#[macro_export]
/// Ask for permission to proceed, but with a custom message.
macro_rules! proceed {
($fll:expr, $msg:expr, $($arg:expr),*) => {{
let formatted = format!(
"{} [{}/{}] ",
i18n_embed_fl::fl!($fll, $msg, $($arg)*),
i18n_embed_fl::fl!($fll, "proceed-affirmative-alt"),
i18n_embed_fl::fl!($fll, "proceed-negative")
);
$crate::utils::prompt($fll, &$crate::a!(formatted))
($fll:expr, $env:expr, $msg:expr, $($arg:expr),*) => {{
if !$env.general.noconfirm {
let formatted = format!(
"{} [{}/{}] ",
i18n_embed_fl::fl!($fll, $msg, $($arg)*),
i18n_embed_fl::fl!($fll, "proceed-affirmative-alt"),
i18n_embed_fl::fl!($fll, "proceed-negative")
);
$crate::utils::prompt($fll, &$crate::a!(formatted))
} else {
Some(())
}
}};
($fll:expr, $msg:expr) => {{
let formatted = format!(
"{} [{}/{}] ",
i18n_embed_fl::fl!($fll, $msg),
i18n_embed_fl::fl!($fll, "proceed-affirmative-alt"),
i18n_embed_fl::fl!($fll, "proceed-negative")
);
$crate::utils::prompt($fll, &$crate::a!(formatted))
($fll:expr, $env:expr, $msg:expr) => {{
if !$env.general.noconfirm {
let formatted = format!(
"{} [{}/{}] ",
i18n_embed_fl::fl!($fll, $msg),
i18n_embed_fl::fl!($fll, "proceed-affirmative-alt"),
i18n_embed_fl::fl!($fll, "proceed-negative")
);
$crate::utils::prompt($fll, &$crate::a!(formatted))
} else {
Some(())
}
}};
}
4 changes: 1 addition & 3 deletions rust/aura-pm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ fn work(args: Args, env: Env, fll: &FluentLanguageLoader) -> Result<(), Error> {
a.packages.iter().map(|s| s.as_str()),
)?,
// --- Package Sets --- //
SubCmd::Backup(b) if b.clean => {
snapshot::clean(fll, &env.caches(), &env.backups.snapshots)?
}
SubCmd::Backup(b) if b.clean => snapshot::clean(fll, &env)?,
SubCmd::Backup(b) if b.list => snapshot::list(&env.backups.snapshots)?,
SubCmd::Backup(b) if b.restore => snapshot::restore(&env, fll, &env.alpm()?)?,
SubCmd::Backup(_) => snapshot::save(fll, &env.alpm()?, &env.backups.snapshots)?,
Expand Down

0 comments on commit e0d2137

Please sign in to comment.