ggen_cli_lib/cmds/
mod.rs

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