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();