ggen_cli_lib/cmds/hook/
mod.rs

1use clap::{Args, Subcommand};
2use ggen_utils::error::Result;
3
4// Declare verb modules
5pub mod create;
6pub mod list;
7pub mod remove;
8pub mod run;
9pub mod validate;
10
11#[derive(Args, Debug)]
12pub struct HookCmd {
13    #[command(subcommand)]
14    pub verb: Verb,
15}
16
17#[derive(Subcommand, Debug)]
18pub enum Verb {
19    /// Create a new knowledge hook for automatic graph regeneration
20    ///
21    /// Examples:
22    ///   ggen hook create "pre-commit" --trigger git-pre-commit --template graph-gen.tmpl
23    ///   ggen hook create "post-merge" --trigger git-post-merge --template sync-graph.tmpl
24    ///   ggen hook create "nightly" --trigger cron --schedule "0 2 * * *" --template full-rebuild.tmpl
25    ///   ggen hook create "file-watch" --trigger file-watch --path "src/**/*.rs" --template incremental.tmpl --dry-run
26    Create(create::CreateArgs),
27
28    /// List all knowledge hooks (active, disabled, or all)
29    ///
30    /// Examples:
31    ///   ggen hook list
32    ///   ggen hook list --active
33    ///   ggen hook list --disabled
34    ///   ggen hook list --json
35    List(list::ListArgs),
36
37    /// Manually run a knowledge hook (for testing or manual execution)
38    ///
39    /// Examples:
40    ///   ggen hook run "pre-commit"
41    ///   ggen hook run "nightly" --dry-run
42    ///   ggen hook run "file-watch" --var changed_file=src/main.rs
43    Run(run::RunArgs),
44
45    /// Remove a knowledge hook and uninstall it from the system
46    ///
47    /// Examples:
48    ///   ggen hook remove "pre-commit"
49    ///   ggen hook remove "nightly" --force
50    Remove(remove::RemoveArgs),
51
52    /// Validate a hook's configuration without running it
53    ///
54    /// Examples:
55    ///   ggen hook validate "pre-commit"
56    ///   ggen hook validate "nightly" --json
57    Validate(validate::ValidateArgs),
58}
59
60impl HookCmd {
61    pub async fn run(&self) -> Result<()> {
62        match &self.verb {
63            Verb::Create(args) => create::run(args).await,
64            Verb::List(args) => list::run(args).await,
65            Verb::Run(args) => run::run(args).await,
66            Verb::Remove(args) => remove::run(args).await,
67            Verb::Validate(args) => validate::run(args).await,
68        }
69    }
70}