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
34// CRITICAL: Force the sync module to be linked so its #[verb] registration works
35// Without this import, the linker optimizes away the linkme static items from #[verb] macro
36#[allow(unused_imports)]
37use sync as _;
38
39use ggen_utils::error::Result;
40use serde_json::json;
41
42use crate::debug_log;
43
44/// Setup and run the command router using clap-noun-verb auto-discovery
45///
46/// ggen v5 has ONE command: `ggen sync`. All verb functions are discovered
47/// automatically via the `#[verb]` macro.
48pub fn run_cli() -> Result<()> {
49 // Handle --version flag before delegating to clap-noun-verb
50 let args: Vec<String> = std::env::args().collect();
51
52 debug_log(
53 "H6",
54 "cmds/mod.rs:run_cli:entry",
55 "run_cli entry with args",
56 json!({ "args": args.clone() }),
57 );
58
59 if args.iter().any(|arg| arg == "--version" || arg == "-V") {
60 log::info!("ggen {}", env!("CARGO_PKG_VERSION"));
61 debug_log(
62 "H6",
63 "cmds/mod.rs:run_cli:version",
64 "handled version flag",
65 json!({}),
66 );
67 return Ok(());
68 }
69
70 // Use clap-noun-verb's auto-discovery to find all [verb] functions
71 debug_log(
72 "H7",
73 "cmds/mod.rs:run_cli:router",
74 "delegating to clap_noun_verb::run",
75 json!({}),
76 );
77
78 clap_noun_verb::run()
79 .map_err(|e| ggen_utils::error::Error::new(&format!("CLI execution failed: {}", e)))?;
80
81 debug_log(
82 "H7",
83 "cmds/mod.rs:run_cli:router",
84 "clap_noun_verb::run completed",
85 json!({}),
86 );
87
88 Ok(())
89}