From 3caab3233df1803312f2f77c031f327eff3fbc03 Mon Sep 17 00:00:00 2001 From: Finjineersdev Date: Sat, 28 Nov 2026 03:09:41 +0500 Subject: [PATCH] fix(cli): refuse pin --days 0 and --days without a folder `opensweep pin FOLDER --days 0` printed "Pinned ... for 0 days" and wrote a pin that had already ended, so the project was judged as usual. `opensweep pin --days 7` with no folder listed the pins and dropped --days without a word. Both are now usage errors and nothing is written. The app only pins for 30 days or for good, so it is not affected. Also gives the FOLDER argument of pin and unpin a help line; `--help` showed it blank. Co-Authored-By: Claude Opus 5.5 --- engine/crates/opensweep-cli/src/main.rs | 17 ++++++++++++++--- engine/crates/opensweep-cli/tests/cli.rs | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/engine/crates/opensweep-cli/src/main.rs b/engine/crates/opensweep-cli/src/main.rs index 18e4f85..9a331e4 100644 --- a/engine/crates/opensweep-cli/src/main.rs +++ b/engine/crates/opensweep-cli/src/main.rs @@ -118,9 +118,17 @@ enum Cmd { }, /// Never clean this folder or anything inside it; with no folder, list pins Pin { + /// Folder to pin folder: Option, - /// Only for this many days; then the project is judged as usual - #[arg(long, value_name = "N", conflicts_with = "remote")] + /// Only for this many days (at least 1); then the project is judged + /// as usual + #[arg( + long, + value_name = "N", + conflicts_with = "remote", + requires = "folder", + value_parser = clap::value_parser!(u64).range(1..) + )] days: Option, /// Pin the folder's git repository (its origin remote) wherever it /// is cloned, instead of this path @@ -128,7 +136,10 @@ enum Cmd { remote: bool, }, /// Remove a pin - Unpin { folder: PathBuf }, + Unpin { + /// Folder (or clone of a pinned repository) to unpin + folder: PathBuf, + }, /// Show the settings, or change them. Changes only OpenSweep's config. Config { /// Projects changed within this many days are Active diff --git a/engine/crates/opensweep-cli/tests/cli.rs b/engine/crates/opensweep-cli/tests/cli.rs index 3202f75..f2d3d67 100644 --- a/engine/crates/opensweep-cli/tests/cli.rs +++ b/engine/crates/opensweep-cli/tests/cli.rs @@ -243,6 +243,24 @@ fn pinned_projects_are_never_cleaned() { assert!(e.clean(&[]).contains("Dry run: 1 folder")); } +#[test] +fn a_pin_for_days_needs_a_folder_and_at_least_one_day() { + let e = env(); + let project = e.project.to_str().unwrap(); + // A pin for 0 days would end the moment it was made. + let zero = e.run(&["pin", project, "--days", "0"]); + assert!(!zero.status.success()); + // Without a folder, pin only lists: --days would be dropped silently. + assert!(!e.run(&["pin", "--days", "7"]).status.success()); + assert!( + !config_file(&e).exists(), + "a refused pin must not write config" + ); + assert!(e + .ok(&["pin", project, "--days", "1"]) + .contains("for 1 days")); +} + #[test] fn a_broken_config_stops_cleaning() { let e = env();