Skip to main content

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/// Shared JSON helper for M1-scaffold stubs.
17///
18/// Emits `{"status": "unimplemented", "verb": "<name>"}` so that
19/// `--json` callers still receive a parseable document when the verb
20/// has not yet been implemented (issue #35 / M8-6). Human-output
21/// behaviour is preserved on the non-JSON path.
22pub(crate) fn emit_unimplemented_json(verb: &str) -> anyhow::Result<()> {
23    let doc = serde_json::json!({
24        "status": "unimplemented",
25        "verb": verb,
26    });
27    println!("{}", serde_json::to_string(&doc)?);
28    Ok(())
29}
30
31/// v1.3.1 B2 — Resolve a verb's `<pack_root>` positional with cwd
32/// default when the operator runs the verb from inside a pack root.
33///
34/// Returns the explicit positional when set; otherwise falls back to
35/// `std::env::current_dir()` ONLY when the cwd carries the pack-marker
36/// `.grex/pack.yaml`. Returns `None` to preserve the legacy
37/// "<pack_root> required" usage error for cwd that lacks the marker.
38///
39/// Mirrors how `git` tools (e.g. `git status`) default to cwd when
40/// `.git/` is present without forcing the operator to repeat the path.
41pub(crate) fn resolve_pack_root_or_cwd(
42    explicit: Option<&std::path::Path>,
43) -> Option<std::path::PathBuf> {
44    if let Some(p) = explicit {
45        return Some(p.to_path_buf());
46    }
47    let cwd = std::env::current_dir().ok()?;
48    if cwd.join(".grex").join("pack.yaml").is_file() {
49        Some(cwd)
50    } else {
51        None
52    }
53}