ggen_cli_lib/cmds/
mod.rs

1//! Command Router Module - ggen v5.0.0 (Fresh Start)
2//!
3//! ggen v5 has ONE command: `ggen sync`. All other commands have been removed
4//! for a fresh start. Utility commands may be added back incrementally in future versions.
5//!
6//! ## The Only Command
7//!
8//! ```bash
9//! ggen sync [OPTIONS]
10//! ```
11//!
12//! ## Removed Commands
13//!
14//! The following commands were removed in v5.0:
15//! - `ggen generate` → Use `ggen sync`
16//! - `ggen validate` → Use `ggen sync --validate-only`
17//! - `ggen template *` → Use `ggen sync`
18//! - `ggen project *` → Add back in v5.1+
19//! - `ggen graph *` → Add back in v5.1+
20//! - `ggen ontology *` → Add back in v5.1+
21//! - `ggen marketplace *` → Add back in v5.1+
22//! - `ggen ai *` → Add back in v5.1+
23//! - `ggen test *` → Add back in v5.1+
24//! - `ggen utils *` → Add back in v5.1+
25//! - `ggen ci *` → Add back in v5.1+
26//! - `ggen workflow *` → Add back in v5.1+
27
28// Shared helpers for command modules
29pub mod helpers;
30
31// THE ONLY COMMAND: ggen sync
32pub mod sync;
33
34use ggen_utils::error::Result;
35use serde_json::json;
36
37use crate::debug_log;
38
39/// Setup and run the command router using clap-noun-verb auto-discovery
40///
41/// ggen v5 has ONE command: `ggen sync`. All verb functions are discovered
42/// automatically via the `#[verb]` macro.
43pub fn run_cli() -> Result<()> {
44    // Handle --version flag before delegating to clap-noun-verb
45    let args: Vec<String> = std::env::args().collect();
46
47    debug_log(
48        "H6",
49        "cmds/mod.rs:run_cli:entry",
50        "run_cli entry with args",
51        json!({ "args": args.clone() }),
52    );
53
54    if args.iter().any(|arg| arg == "--version" || arg == "-V") {
55        log::info!("ggen {}", env!("CARGO_PKG_VERSION"));
56        debug_log(
57            "H6",
58            "cmds/mod.rs:run_cli:version",
59            "handled version flag",
60            json!({}),
61        );
62        return Ok(());
63    }
64
65    // Use clap-noun-verb's auto-discovery to find all [verb] functions
66    debug_log(
67        "H7",
68        "cmds/mod.rs:run_cli:router",
69        "delegating to clap_noun_verb::run",
70        json!({}),
71    );
72
73    clap_noun_verb::run()
74        .map_err(|e| ggen_utils::error::Error::new(&format!("CLI execution failed: {}", e)))?;
75
76    debug_log(
77        "H7",
78        "cmds/mod.rs:run_cli:router",
79        "clap_noun_verb::run completed",
80        json!({}),
81    );
82
83    Ok(())
84}