grex_cli/cli/args.rs
1use clap::{Args, Parser, Subcommand};
2
3#[derive(Parser, Debug)]
4#[command(
5 name = "grex",
6 version,
7 about = "grex — nested meta-repo manager. Pack-based, agent-native, Rust-fast.",
8 long_about = "grex manages trees of git repositories as a single addressable graph. \
9 Each node is a \"pack\" — a plain git repo plus a `.grex/` contract — and every \
10 pack is a meta-pack by construction (zero children = leaf, N children = orchestrator \
11 of N more packs, recursively). One uniform command surface (`sync`, `add`, `rm`, \
12 `update`, `status`, `import`, `doctor`, `teardown`, `exec`, `run`, `serve`) operates \
13 over the whole graph regardless of depth."
14)]
15pub struct Cli {
16 #[command(flatten)]
17 pub global: GlobalFlags,
18
19 #[command(subcommand)]
20 pub verb: Verb,
21}
22
23#[derive(Args, Debug)]
24pub struct GlobalFlags {
25 /// Emit output as JSON.
26 #[arg(long, global = true, conflicts_with = "plain")]
27 pub json: bool,
28
29 /// Emit plain (non-color, non-table) output.
30 #[arg(long, global = true)]
31 pub plain: bool,
32
33 /// Show planned actions without executing them.
34 #[arg(long, global = true)]
35 pub dry_run: bool,
36
37 /// Filter packs by expression.
38 #[arg(long, global = true)]
39 pub filter: Option<String>,
40}
41
42#[derive(Subcommand, Debug)]
43pub enum Verb {
44 /// Initialize a grex workspace.
45 Init(InitArgs),
46 /// Register and clone a pack.
47 Add(AddArgs),
48 /// Teardown and remove a pack.
49 Rm(RmArgs),
50 /// List registered packs.
51 Ls(LsArgs),
52 /// Report drift vs lockfile.
53 Status(StatusArgs),
54 /// Git fetch and pull (recurse by default).
55 Sync(SyncArgs),
56 /// Sync plus re-run install on lock change.
57 Update(UpdateArgs),
58 /// Run integrity checks.
59 Doctor(DoctorArgs),
60 /// Start MCP stdio server.
61 Serve(ServeArgs),
62 /// Import legacy REPOS.json.
63 Import(ImportArgs),
64 /// Run a named action across packs.
65 Run(RunArgs),
66 /// Execute a shell command in pack context.
67 Exec(ExecArgs),
68 /// Tear down a pack tree (reverse of `sync`/`install`).
69 Teardown(TeardownArgs),
70 /// Migrate a v1.1.x lockfile in place to the v1.2.0 schema (opt-in,
71 /// idempotent). Thin shim over the v1.2.0 Stage 1.h library
72 /// migrator (`grex_core::lockfile::migrate_v1_1_1`).
73 #[command(name = "migrate-lockfile")]
74 MigrateLockfile(MigrateLockfileArgs),
75}
76
77#[derive(Args, Debug)]
78pub struct InitArgs {}
79
80#[derive(Args, Debug)]
81pub struct AddArgs {
82 /// Git URL of the pack repo.
83 pub url: String,
84 /// Optional local path (defaults to repo name).
85 pub path: Option<String>,
86}
87
88#[derive(Args, Debug)]
89pub struct RmArgs {
90 /// Local path of the pack to remove.
91 pub path: String,
92}
93
94#[derive(Args, Debug)]
95pub struct LsArgs {
96 /// Pack root. Directory holding `.grex/pack.yaml`, or the YAML file
97 /// itself. Defaults to the current working directory.
98 pub pack_root: Option<std::path::PathBuf>,
99}
100
101#[derive(Args, Debug)]
102pub struct StatusArgs {}
103
104#[derive(Args, Debug)]
105pub struct SyncArgs {
106 /// Recurse into child packs.
107 #[arg(long, default_value_t = true)]
108 pub recursive: bool,
109
110 /// Pack root. Directory holding `.grex/pack.yaml`, or the YAML file
111 /// itself. When omitted, `sync` prints the legacy M1 stub and exits 0.
112 pub pack_root: Option<std::path::PathBuf>,
113
114 /// Override the workspace root. Defaults to the pack root directory
115 /// (where `.grex/pack.yaml` lives). When set, this path becomes the
116 /// canonical meta directory: children resolve parent-relatively as
117 /// `<workspace>/<child.path>`. The path MUST exist; symlinks are
118 /// resolved to their canonical inode (logged as `workspace: <input>
119 /// → <canonical>` when it differs).
120 #[arg(long)]
121 pub workspace: Option<std::path::PathBuf>,
122
123 /// Plan actions without touching the filesystem.
124 #[arg(long, short = 'n')]
125 pub dry_run: bool,
126
127 /// Suppress per-action log lines.
128 #[arg(long, short = 'q')]
129 pub quiet: bool,
130
131 /// Skip plan-phase validators. Debug-only escape hatch.
132 #[arg(long)]
133 pub no_validate: bool,
134
135 /// Override the default ref for every pack in this sync invocation.
136 /// Accepts a branch, tag, or commit SHA. Empty strings are rejected.
137 #[arg(long = "ref", value_name = "REF", value_parser = non_empty_string)]
138 pub ref_override: Option<String>,
139
140 /// Restrict sync to packs whose workspace-relative path (or name)
141 /// matches the glob. Repeat the flag to OR-combine multiple patterns
142 /// (standard `*`/`**`/`?` semantics). Non-matching packs are skipped
143 /// entirely — no action execution, no lockfile write.
144 #[arg(long = "only", value_name = "GLOB", value_parser = non_empty_string)]
145 pub only: Vec<String>,
146
147 /// Re-execute every pack even when its `actions_hash` is unchanged
148 /// from the prior lockfile. Overrides the M4-B skip-on-hash
149 /// short-circuit; dry-run semantics are unchanged.
150 #[arg(long)]
151 pub force: bool,
152
153 /// v1.2.0 Stage 1.l — Override Phase 2 prune-safety refusal for
154 /// dirty (tracked or untracked-non-ignored) working trees. Still
155 /// refuses ignored content unless `--force-prune-with-ignored` is
156 /// also set. Never overrides `GitInProgress` (mid-rebase / merge /
157 /// cherry-pick / revert / bisect).
158 #[arg(long = "force-prune")]
159 pub force_prune: bool,
160
161 /// v1.2.0 Stage 1.l — Strongest prune override. Implies
162 /// `--force-prune` and additionally drops trees whose only dirt is
163 /// in `--ignored` paths (build artefacts, `target/`, `node_modules/`).
164 /// Never overrides `GitInProgress`.
165 #[arg(long = "force-prune-with-ignored")]
166 pub force_prune_with_ignored: bool,
167
168 /// v1.2.1 Item 5b — Recursively snapshot Phase 2 prune targets to
169 /// `<meta>/.grex/trash/<ISO8601>/<basename>/` BEFORE deletion.
170 /// Audit log entry (`QuarantineStart`) is appended + fsync'd
171 /// before any byte is copied; on snapshot failure the prune
172 /// aborts and the original dest is left intact for forensics.
173 /// Requires `--force-prune` or `--force-prune-with-ignored` —
174 /// quarantine only applies to overridden prunes; clean-consent
175 /// prunes still go through the direct-unlink fast path. The
176 /// "requires one of" check is enforced in the verb handler
177 /// (see `crates/grex/src/cli/verbs/sync.rs`) since clap's
178 /// `requires`/`required_unless_present_any` semantics don't
179 /// model "X requires (A or B)" cleanly without an `ArgGroup`.
180 /// Matches Lean theorem `quarantine_snapshot_precedes_delete`.
181 #[arg(long = "quarantine")]
182 pub quarantine: bool,
183
184 /// Max parallel pack ops during this sync run (feat-m6-1).
185 ///
186 /// Semantics:
187 /// * Absent → default `num_cpus::get()` resolved in `verbs::sync`.
188 /// * `0` → unbounded (`Semaphore::MAX_PERMITS`).
189 /// * `1` → serial fast-path (preserves pre-M6 wall-order).
190 /// * `2..=1024` → bounded parallel.
191 ///
192 /// Env fallback: `GREX_PARALLEL` is honoured only when the flag is
193 /// absent. Clap reads the env var automatically via `env`.
194 ///
195 /// Distinct from the global `--parallel` on [`GlobalFlags`]; that
196 /// knob is documented as the harness-level worker cap and rejects
197 /// `0`. Sync parallelism uses `0` as the "unbounded" sentinel per
198 /// `.omne/cfg/concurrency.md`.
199 #[arg(
200 long = "parallel",
201 env = "GREX_PARALLEL",
202 value_parser = clap::value_parser!(u32).range(0..=1024),
203 )]
204 pub parallel: Option<u32>,
205
206 /// v1.2.5 — sweep `<meta>/.grex/trash/` of entries older than
207 /// `N` days at the start of every meta sync (best-effort). When
208 /// omitted, no GC fires (v1.2.1 indefinite-retention behavior is
209 /// preserved). When set, sweep failures log via tracing and do
210 /// NOT halt the sync.
211 #[arg(long = "retain-days", value_name = "N")]
212 pub retain_days: Option<u32>,
213}
214
215/// Clap `value_parser` that rejects empty or whitespace-only strings.
216/// Keeps `--ref ""`, `--ref " "`, `--only ""`, `--only "\t"` off the
217/// fast path. Whitespace-only values are rejected because they
218/// degrade silently inside the walker / globset layers rather than
219/// producing a useful error.
220fn non_empty_string(s: &str) -> Result<String, String> {
221 if s.trim().is_empty() {
222 Err("value must not be empty or whitespace-only".to_string())
223 } else {
224 Ok(s.to_string())
225 }
226}
227
228#[derive(Args, Debug)]
229pub struct UpdateArgs {
230 /// Optional pack path; if omitted, update all.
231 pub pack: Option<String>,
232}
233
234#[derive(Args, Debug)]
235pub struct DoctorArgs {
236 /// Heal gitignore drift by re-emitting the managed block. Safety:
237 /// NEVER touches the manifest or the filesystem on other checks.
238 #[arg(long)]
239 pub fix: bool,
240
241 /// Run the opt-in config-lint check (`openspec/config.yaml` +
242 /// `.omne/cfg/*.md`). Skipped by default.
243 #[arg(long = "lint-config")]
244 pub lint_config: bool,
245
246 /// v1.2.0 Stage 1.j — bound the recursive ManifestTree walk.
247 /// Omitted: walk every nested meta exhaustively (default).
248 /// `--shallow 0`: root meta only.
249 /// `--shallow N`: recurse up to `N` levels of nesting (root is
250 /// depth 0; depth-`N` metas are visited but their children are
251 /// not). The walk is read-only at every frame.
252 #[arg(long = "shallow", value_name = "N")]
253 pub shallow: Option<usize>,
254
255 /// v1.2.1 item 4 — opt-in full-filesystem scan for `.git/`
256 /// directories that are not registered in the manifest tree.
257 /// Read-only audit; complements the manifest-driven default walk.
258 /// Composes with `--shallow` (which bounds the manifest walk).
259 /// Use `--depth N` to bound the filesystem scan independently.
260 #[arg(long = "scan-undeclared")]
261 pub scan_undeclared: bool,
262
263 /// v1.2.1 item 4 — bound the `--scan-undeclared` filesystem walk.
264 /// Omitted: scan every level under the workspace (default).
265 /// `--depth 0`: workspace root only.
266 /// `--depth N`: descend up to `N` directory levels below the
267 /// workspace root. Has no effect unless `--scan-undeclared` is
268 /// also set.
269 #[arg(long = "depth", value_name = "N", requires = "scan_undeclared")]
270 pub depth: Option<usize>,
271
272 /// v1.2.5 — sweep `<workspace>/.grex/trash/` of entries older than
273 /// the supplied retention window (in days). Pairs with the
274 /// canonical retention default surfaced by
275 /// [`grex_core::tree::DEFAULT_RETAIN_DAYS`] when the operator
276 /// omits a value. Best-effort: per-entry failures log via
277 /// `tracing::warn!` and do not halt the doctor run.
278 #[arg(long = "prune-quarantine")]
279 pub prune_quarantine: bool,
280
281 /// v1.2.5 — explicit retention window for `--prune-quarantine`
282 /// (and `grex sync`'s GC sweep). Defaults to
283 /// [`grex_core::tree::DEFAULT_RETAIN_DAYS`] when `--prune-quarantine`
284 /// is set without an explicit value. Has no effect unless
285 /// `--prune-quarantine` is also passed (or threaded into
286 /// `grex sync` via the matching flag there).
287 #[arg(long = "retain-days", value_name = "N")]
288 pub retain_days: Option<u32>,
289
290 /// v1.2.5 — restore the snapshot at
291 /// `<workspace>/.grex/trash/<TS>/<BASENAME>/` back into the
292 /// workspace. When BASENAME is omitted the `<TS>/` slot must hold
293 /// exactly one child entry (otherwise restore is refused as
294 /// ambiguous). Refuses to clobber an existing dest unless
295 /// `--force` is also passed.
296 #[arg(long = "restore-quarantine", value_name = "TS[:BASENAME]", num_args = 1)]
297 pub restore_quarantine: Option<String>,
298
299 /// v1.2.5 — paired with `--restore-quarantine`: when set, remove
300 /// the existing dest before the rename. Without this flag,
301 /// restore refuses to clobber an existing dest.
302 #[arg(long = "force", requires = "restore_quarantine")]
303 pub force: bool,
304}
305
306#[derive(Args, Debug)]
307pub struct ServeArgs {
308 /// Path to the `.grex/events.jsonl` event log. Captured at server
309 /// launch and immutable for the session (per spec §"Manifest binding").
310 /// Defaults to `<workspace>/.grex/events.jsonl` when omitted, where
311 /// `<workspace>` is resolved by walking up from cwd to the nearest
312 /// `.grex/` marker. v1.x `<workspace>/grex.jsonl` event logs are
313 /// auto-migrated to the canonical location on first access.
314 #[arg(long, value_name = "PATH")]
315 pub manifest: Option<std::path::PathBuf>,
316
317 /// Workspace root the MCP server resolves relative paths against.
318 /// Defaults to the current working directory when omitted.
319 #[arg(long, value_name = "PATH")]
320 pub workspace: Option<std::path::PathBuf>,
321
322 /// Harness-level worker cap inherited by the MCP server's
323 /// `Scheduler` (feat-m7-1 stage 8.3). `1` = serial; range `1..=1024`.
324 /// Defaults to `std::thread::available_parallelism()` when omitted.
325 /// Distinct from `sync --parallel` which uses `0` = unbounded.
326 #[arg(
327 long = "parallel",
328 value_parser = clap::value_parser!(u32).range(1..=1024),
329 )]
330 pub parallel: Option<u32>,
331}
332
333#[derive(Args, Debug)]
334pub struct ImportArgs {
335 /// Path to a legacy REPOS.json file.
336 #[arg(long)]
337 pub from_repos_json: Option<std::path::PathBuf>,
338
339 /// Target event log (`.grex/events.jsonl`). Defaults to
340 /// `<workspace>/.grex/events.jsonl` where `<workspace>` is resolved
341 /// by walking up from cwd to the nearest `.grex/` marker.
342 #[arg(long, value_name = "PATH")]
343 pub manifest: Option<std::path::PathBuf>,
344
345 /// Verb-scoped dry-run. Alias for the global `--dry-run`; either
346 /// flag short-circuits before any manifest write.
347 #[arg(long = "dry-run", short = 'n')]
348 pub dry_run: bool,
349}
350
351#[derive(Args, Debug)]
352pub struct RunArgs {
353 /// Action name to run.
354 pub action: String,
355}
356
357#[derive(Args, Debug)]
358pub struct ExecArgs {
359 /// Shell command and args to execute.
360 #[arg(trailing_var_arg = true)]
361 pub cmd: Vec<String>,
362}
363
364#[derive(Args, Debug)]
365pub struct MigrateLockfileArgs {
366 /// Workspace root (the meta whose `.grex/grex.lock.jsonl` to
367 /// migrate). Defaults to the current working directory.
368 #[arg(long, value_name = "PATH")]
369 pub workspace: Option<std::path::PathBuf>,
370
371 /// Inspect-only: detect schema version and report what would happen
372 /// without writing. Lockfile bytes are unchanged.
373 #[arg(long = "dry-run", short = 'n')]
374 pub dry_run: bool,
375}
376
377#[derive(Args, Debug)]
378pub struct TeardownArgs {
379 /// Pack root. Directory holding `.grex/pack.yaml`, or the YAML file
380 /// itself. When omitted, `teardown` prints a usage stub and exits 0.
381 pub pack_root: Option<std::path::PathBuf>,
382
383 /// Override the workspace root. Defaults to the pack root directory
384 /// (where `.grex/pack.yaml` lives). When set, this path becomes the
385 /// canonical meta directory: children resolve parent-relatively as
386 /// `<workspace>/<child.path>`. The path MUST exist; symlinks are
387 /// resolved to their canonical inode (logged as `workspace: <input>
388 /// → <canonical>` when it differs).
389 #[arg(long)]
390 pub workspace: Option<std::path::PathBuf>,
391
392 /// Suppress per-action log lines.
393 #[arg(long, short = 'q')]
394 pub quiet: bool,
395
396 /// Skip plan-phase validators. Debug-only escape hatch.
397 #[arg(long)]
398 pub no_validate: bool,
399}
400
401#[cfg(test)]
402mod tests {
403 //! Direct-parse unit tests. These bypass the spawned binary and hit
404 //! `Cli::try_parse_from` in-process — much faster than `assert_cmd`.
405 use super::*;
406 use clap::Parser;
407
408 fn parse(args: &[&str]) -> Result<Cli, clap::Error> {
409 // clap's `try_parse_from` expects argv[0] to be the binary name.
410 let mut full = vec!["grex"];
411 full.extend_from_slice(args);
412 Cli::try_parse_from(full)
413 }
414
415 #[test]
416 fn init_parses_to_init_variant() {
417 let cli = parse(&["init"]).expect("init parses");
418 assert!(matches!(cli.verb, Verb::Init(_)));
419 }
420
421 #[test]
422 fn add_parses_url_and_optional_path() {
423 let cli = parse(&["add", "https://example.com/repo.git"]).expect("add url parses");
424 match cli.verb {
425 Verb::Add(a) => {
426 assert_eq!(a.url, "https://example.com/repo.git");
427 assert!(a.path.is_none());
428 }
429 _ => panic!("expected Add variant"),
430 }
431
432 let cli = parse(&["add", "https://example.com/repo.git", "local"])
433 .expect("add url + path parses");
434 match cli.verb {
435 Verb::Add(a) => {
436 assert_eq!(a.url, "https://example.com/repo.git");
437 assert_eq!(a.path.as_deref(), Some("local"));
438 }
439 _ => panic!("expected Add variant"),
440 }
441 }
442
443 #[test]
444 fn rm_parses_path() {
445 let cli = parse(&["rm", "pack-a"]).expect("rm parses");
446 match cli.verb {
447 Verb::Rm(a) => assert_eq!(a.path, "pack-a"),
448 _ => panic!("expected Rm variant"),
449 }
450 }
451
452 #[test]
453 fn sync_recursive_defaults_to_true() {
454 let cli = parse(&["sync"]).expect("sync parses");
455 match cli.verb {
456 Verb::Sync(a) => assert!(a.recursive, "sync should default to recursive=true"),
457 _ => panic!("expected Sync variant"),
458 }
459 }
460
461 #[test]
462 fn update_pack_is_optional() {
463 let cli = parse(&["update"]).expect("update parses bare");
464 match cli.verb {
465 Verb::Update(a) => assert!(a.pack.is_none()),
466 _ => panic!("expected Update variant"),
467 }
468
469 let cli = parse(&["update", "mypack"]).expect("update parses w/ pack");
470 match cli.verb {
471 Verb::Update(a) => assert_eq!(a.pack.as_deref(), Some("mypack")),
472 _ => panic!("expected Update variant"),
473 }
474 }
475
476 #[test]
477 fn exec_collects_trailing_args() {
478 let cli = parse(&["exec", "echo", "hi", "there"]).expect("exec parses");
479 match cli.verb {
480 Verb::Exec(a) => assert_eq!(a.cmd, vec!["echo", "hi", "there"]),
481 _ => panic!("expected Exec variant"),
482 }
483 }
484
485 #[test]
486 fn universal_flags_populate_on_any_verb() {
487 // `--json` and `--plain` are mutually exclusive, so split into two
488 // parses to exercise the remaining flags on both modes.
489 let cli = parse(&["ls", "--json", "--dry-run", "--filter", "kind=git"])
490 .expect("ls w/ json+dry-run+filter parses");
491 assert!(cli.global.json);
492 assert!(!cli.global.plain);
493 assert!(cli.global.dry_run);
494 assert_eq!(cli.global.filter.as_deref(), Some("kind=git"));
495
496 let cli = parse(&["ls", "--plain", "--dry-run"]).expect("ls w/ plain+dry-run parses");
497 assert!(!cli.global.json);
498 assert!(cli.global.plain);
499 }
500
501 #[test]
502 fn json_and_plain_conflict() {
503 let err =
504 parse(&["init", "--json", "--plain"]).expect_err("--json and --plain must conflict");
505 assert_eq!(err.kind(), clap::error::ErrorKind::ArgumentConflict);
506 }
507
508 #[test]
509 fn parallel_not_global_rejected_on_non_sync_verb() {
510 // feat-m6 B2 — `--parallel` is sync-scoped only; it must NOT
511 // be accepted as a global flag on verbs like `init`/`ls`.
512 let err =
513 parse(&["init", "--parallel", "1"]).expect_err("--parallel on non-sync verb must fail");
514 assert_eq!(err.kind(), clap::error::ErrorKind::UnknownArgument);
515 }
516
517 #[test]
518 fn sync_parallel_one_accepted() {
519 let cli = parse(&["sync", "--parallel", "1"]).expect("sync --parallel 1 parses");
520 match cli.verb {
521 Verb::Sync(a) => assert_eq!(a.parallel, Some(1)),
522 _ => panic!("expected Sync variant"),
523 }
524 }
525
526 #[test]
527 fn sync_parallel_max_accepted() {
528 let cli = parse(&["sync", "--parallel", "1024"]).expect("sync --parallel 1024 parses");
529 match cli.verb {
530 Verb::Sync(a) => assert_eq!(a.parallel, Some(1024)),
531 _ => panic!("expected Sync variant"),
532 }
533 }
534
535 #[test]
536 fn sync_parallel_over_max_rejected() {
537 let err =
538 parse(&["sync", "--parallel", "1025"]).expect_err("sync --parallel 1025 must fail");
539 assert_eq!(err.kind(), clap::error::ErrorKind::ValueValidation);
540 }
541
542 #[test]
543 fn import_from_repos_json_parses_as_pathbuf() {
544 let cli =
545 parse(&["import", "--from-repos-json", "./REPOS.json"]).expect("import parses path");
546 match cli.verb {
547 Verb::Import(a) => {
548 assert_eq!(
549 a.from_repos_json.as_deref(),
550 Some(std::path::Path::new("./REPOS.json"))
551 );
552 }
553 _ => panic!("expected Import variant"),
554 }
555 }
556
557 #[test]
558 fn run_requires_action() {
559 let err = parse(&["run"]).expect_err("run w/o action must fail");
560 assert_eq!(err.kind(), clap::error::ErrorKind::MissingRequiredArgument);
561 }
562
563 #[test]
564 fn unknown_verb_fails() {
565 let err = parse(&["nope"]).expect_err("unknown verb must fail");
566 assert_eq!(err.kind(), clap::error::ErrorKind::InvalidSubcommand);
567 }
568
569 #[test]
570 fn unknown_flag_fails() {
571 let err = parse(&["init", "--not-a-flag"]).expect_err("unknown flag must fail");
572 assert_eq!(err.kind(), clap::error::ErrorKind::UnknownArgument);
573 }
574
575 #[test]
576 fn test_cli_force_prune_flag_parsed() {
577 // v1.2.0 Stage 1.l — `--force-prune` toggles the SyncArgs
578 // bool. Default is `false`.
579 let cli = parse(&["sync", "."]).expect("sync . parses");
580 match cli.verb {
581 Verb::Sync(ref a) => {
582 assert!(!a.force_prune, "default --force-prune must be false");
583 assert!(
584 !a.force_prune_with_ignored,
585 "default --force-prune-with-ignored must be false"
586 );
587 }
588 _ => panic!("expected Sync variant"),
589 }
590 let cli = parse(&["sync", ".", "--force-prune"]).expect("sync --force-prune parses");
591 match cli.verb {
592 Verb::Sync(a) => {
593 assert!(a.force_prune, "--force-prune must set true");
594 assert!(
595 !a.force_prune_with_ignored,
596 "--force-prune-with-ignored stays default false"
597 );
598 }
599 _ => panic!("expected Sync variant"),
600 }
601 }
602
603 #[test]
604 fn test_cli_force_prune_with_ignored_flag_parsed() {
605 // v1.2.0 Stage 1.l — `--force-prune-with-ignored` toggles
606 // independently of `--force-prune`. Walker layer interprets the
607 // matrix; CLI just parses the bools.
608 let cli = parse(&["sync", ".", "--force-prune-with-ignored"])
609 .expect("sync --force-prune-with-ignored parses");
610 match cli.verb {
611 Verb::Sync(a) => {
612 assert!(
613 !a.force_prune,
614 "--force-prune is independent of --force-prune-with-ignored at parse layer"
615 );
616 assert!(a.force_prune_with_ignored, "--force-prune-with-ignored must set true");
617 }
618 _ => panic!("expected Sync variant"),
619 }
620 // Both flags together: caller's documented "stronger" combo.
621 let cli = parse(&["sync", ".", "--force-prune", "--force-prune-with-ignored"])
622 .expect("sync --force-prune --force-prune-with-ignored parses");
623 match cli.verb {
624 Verb::Sync(a) => {
625 assert!(a.force_prune);
626 assert!(a.force_prune_with_ignored);
627 }
628 _ => panic!("expected Sync variant"),
629 }
630 }
631
632 #[test]
633 fn cli_non_empty_string_rejects_whitespace() {
634 // F8: `--ref " "` / `--only "\t"` must be rejected by the value
635 // parser, not silently threaded into the walker / globset layer
636 // where they degrade into useless errors.
637 for bad in ["", " ", "\t", " ", "\n"] {
638 let err =
639 parse(&["sync", ".", "--ref", bad]).expect_err("whitespace --ref must be rejected");
640 assert_eq!(err.kind(), clap::error::ErrorKind::ValueValidation, "for {bad:?}");
641
642 let err = parse(&["sync", ".", "--only", bad])
643 .expect_err("whitespace --only must be rejected");
644 assert_eq!(err.kind(), clap::error::ErrorKind::ValueValidation, "for {bad:?}");
645 }
646 }
647}