grex_cli/cli/verbs/mod.rs
1pub mod add;
2pub mod doctor;
3pub mod exec;
4pub mod import;
5pub mod init;
6pub mod ls;
7pub mod migrate_lockfile;
8pub mod rm;
9pub mod run;
10pub mod serve;
11pub mod status;
12pub mod sync;
13pub mod teardown;
14pub mod update;
15
16/// v1.3.1 B2 — Resolve a verb's `<pack_root>` positional with cwd
17/// default when the operator runs the verb from inside a pack root.
18///
19/// Returns the explicit positional when set; otherwise falls back to
20/// `std::env::current_dir()` ONLY when the cwd carries the pack-marker
21/// `.grex/pack.yaml`. Returns `None` to preserve the legacy
22/// "<pack_root> required" usage error for cwd that lacks the marker.
23///
24/// Mirrors how `git` tools (e.g. `git status`) default to cwd when
25/// `.git/` is present without forcing the operator to repeat the path.
26pub(crate) fn resolve_pack_root_or_cwd(
27 explicit: Option<&std::path::Path>,
28) -> Option<std::path::PathBuf> {
29 if let Some(p) = explicit {
30 return Some(p.to_path_buf());
31 }
32 let cwd = std::env::current_dir().ok()?;
33 if cwd.join(".grex").join("pack.yaml").is_file() {
34 Some(cwd)
35 } else {
36 None
37 }
38}