From 0d24b0a06d65760320d5d0b7a56a25cfc7c80273 Mon Sep 17 00:00:00 2001 From: Vincent de Phily Date: Sat, 24 Feb 2024 09:43:43 +0000 Subject: [PATCH] cli: Bring back `--resume=auto`, rename `any` to `either` Seemed unnecessary and inconsistent to not have an `auto`. --- CHANGELOG.md | 7 +++---- README.md | 2 +- src/commands.rs | 2 +- src/config.rs | 2 +- src/config/cli.rs | 14 +++++++------- src/config/types.rs | 6 +++--- src/parse/current.rs | 14 +++++++------- 7 files changed, 23 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 291431c..e91171c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,10 +17,9 @@ * Support multiple `--tmpdir` arguments * `--tabs` has been renamed `--output=tab/columns/auto` (or `-ot` for short) - Default output is now `columns` on tty and `tab` otherwise, to simplify `emlop ...|cut -f...` workflow -* Added `--resume=any` variant to resume either main or backup list - - Passing `--resume` without argument is now the same as `--resume any` - - Default value remains `main` - - Removed `--resume=auto` variant (just don't pass the option) +* Added `--resume=either` variant to resume either main or backup list + - Passing `--resume` without argument is now the same as `--resume either` + - Default value remains `auto` (use main list if currently emerging) * `--color` variants renamed to `(y)es`, `(n)o`, `(t)ty` * Improved inline help and error messages - Upgraded argument parser dependency diff --git a/README.md b/README.md index ec01daa..e7c10a9 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Predict-specific arguments: -s, --show Show (e)emerge processes, (m)erges, (t)otal, and/or (a)ll -N, --first [] Show only the first entries -n, --last [] Show only the last entries - --resume [] Use main, backup, any, or no portage resume list + --resume [] Use main, backup, either, or no portage resume list Stats: --limit Use the last merge times to predict durations --avg Select function used to predict durations diff --git a/src/commands.rs b/src/commands.rs index 7221e62..af46723 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -297,7 +297,7 @@ pub fn cmd_predict(gc: &Conf, sc: &ConfPred) -> Result { let einfo = get_emerge(&mut tmpdirs); if einfo.cmds.is_empty() && std::io::stdin().is_terminal() - && matches!(sc.resume, ResumeKind::No | ResumeKind::Current) + && matches!(sc.resume, ResumeKind::No | ResumeKind::Auto) { tbl.row([&[&"No ongoing merge found"], &[], &[]]); return Ok(false); diff --git a/src/config.rs b/src/config.rs index 23f9d67..4a0b5c9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -196,7 +196,7 @@ impl ConfPred { avg: sel!(cli, toml, predict, avg, (), Average::Median)?, lim: sel!(cli, toml, predict, limit, 1..65000, 10)? as u16, unknown: sel!(cli, toml, predict, unknown, 0..3600, 10)?, - resume: *cli.get_one("resume").unwrap_or(&ResumeKind::Current), + resume: *cli.get_one("resume").unwrap_or(&ResumeKind::Auto), tmpdirs, first: *cli.get_one("first").unwrap_or(&usize::MAX), last: *cli.get_one("last").unwrap_or(&usize::MAX) }) diff --git a/src/config/cli.rs b/src/config/cli.rs index 9646280..6243e06 100644 --- a/src/config/cli.rs +++ b/src/config/cli.rs @@ -123,19 +123,19 @@ pub fn build_cli_nocomplete() -> Command { .long_help("Show only the last entries\n \ (empty)|1: last entry\n \ 5: last 5 entries\n"); - let h = "Use main, backup, any, or no portage resume list\n\ + let h = "Use main, backup, either, or no portage resume list\n\ This is ignored if STDIN is a piped `emerge -p` output\n \ - (default): Use main resume list, if currently emerging\n \ - any|a|(empty): Use main or backup resume list\n \ - main|m: Use main resume list\n \ - backup|b: Use backup resume list\n \ - no|n: Never use resume list"; + (default)|auto|a: Use main resume list, if currently emerging\n \ + (empty)|either|e: Use main or backup resume list\n \ + main|m: Use main resume list\n \ + backup|b: Use backup resume list\n \ + no|n: Never use resume list"; let resume = Arg::new("resume").long("resume") .value_name("source") .value_parser(value_parser!(crate::config::ResumeKind)) .hide_possible_values(true) .num_args(..=1) - .default_missing_value("any") + .default_missing_value("either") .display_order(8) .help_heading("Filter") .help(h.split_once('\n').unwrap().0) diff --git a/src/config/types.rs b/src/config/types.rs index 98f2a95..09c0587 100644 --- a/src/config/types.rs +++ b/src/config/types.rs @@ -121,10 +121,10 @@ impl ArgParse for Average { #[derive(Clone, Copy, Debug, clap::ValueEnum)] pub enum ResumeKind { - #[clap(hide(true))] - Current, #[clap(alias("a"))] - Any, + Auto, + #[clap(alias("e"))] + Either, #[clap(alias("m"))] Main, #[clap(alias("b"))] diff --git a/src/parse/current.rs b/src/parse/current.rs index c4bf768..48c02f8 100644 --- a/src/parse/current.rs +++ b/src/parse/current.rs @@ -90,8 +90,8 @@ fn get_resume_priv(kind: ResumeKind, file: &str) -> Option> { let reader = File::open(file).map_err(|e| warn!("Cannot open {file:?}: {e}")).ok()?; let db: Mtimedb = from_reader(reader).map_err(|e| warn!("Cannot parse {file:?}: {e}")).ok()?; let r = match kind { - ResumeKind::Any => db.resume.or(db.resume_backup)?, - ResumeKind::Main | ResumeKind::Current => db.resume?, + ResumeKind::Either => db.resume.or(db.resume_backup)?, + ResumeKind::Main | ResumeKind::Auto => db.resume?, ResumeKind::Backup => db.resume_backup?, ResumeKind::No => unreachable!(), }; @@ -219,11 +219,11 @@ mod tests { check_resume(ResumeKind::Main, "mtimedb.ok", Some(main)); check_resume(ResumeKind::Backup, "mtimedb.ok", Some(bkp)); check_resume(ResumeKind::No, "mtimedb.ok", Some(&[])); - check_resume(ResumeKind::Any, "mtimedb.ok", Some(main)); - check_resume(ResumeKind::Any, "mtimedb.backuponly", Some(bkp)); - check_resume(ResumeKind::Any, "mtimedb.empty", Some(&[])); - check_resume(ResumeKind::Any, "mtimedb.noresume", None); - check_resume(ResumeKind::Any, "mtimedb.badjson", None); + check_resume(ResumeKind::Either, "mtimedb.ok", Some(main)); + check_resume(ResumeKind::Either, "mtimedb.backuponly", Some(bkp)); + check_resume(ResumeKind::Either, "mtimedb.empty", Some(&[])); + check_resume(ResumeKind::Either, "mtimedb.noresume", None); + check_resume(ResumeKind::Either, "mtimedb.badjson", None); } #[test]