Skip to content

Commit

Permalink
cli: Bring back --resume=auto, rename any to either
Browse files Browse the repository at this point in the history
Seemed unnecessary and inconsistent to not have an `auto`.
  • Loading branch information
vincentdephily committed Feb 24, 2024
1 parent 951fdf1 commit 0d24b0a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 24 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Predict-specific arguments:
-s, --show <e,m,t,a> Show (e)emerge processes, (m)erges, (t)otal, and/or (a)ll
-N, --first [<num>] Show only the first <num> entries
-n, --last [<num>] Show only the last <num> entries
--resume [<source>] Use main, backup, any, or no portage resume list
--resume [<source>] Use main, backup, either, or no portage resume list
Stats:
--limit <num> Use the last <num> merge times to predict durations
--avg <fn> Select function used to predict durations
Expand Down
2 changes: 1 addition & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub fn cmd_predict(gc: &Conf, sc: &ConfPred) -> Result<bool, Error> {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
Expand Down
14 changes: 7 additions & 7 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ pub fn build_cli_nocomplete() -> Command {
.long_help("Show only the last <num> 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)
Expand Down
6 changes: 3 additions & 3 deletions src/config/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ impl ArgParse<String, ()> 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"))]
Expand Down
14 changes: 7 additions & 7 deletions src/parse/current.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ fn get_resume_priv(kind: ResumeKind, file: &str) -> Option<Vec<Pkg>> {
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!(),
};
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 0d24b0a

Please sign in to comment.