Skip to main content

gn_cli/
lib.rs

1use clap::{Parser, Subcommand};
2use tracing_subscriber::EnvFilter;
3
4pub mod commands;
5
6/// git-notes CLI — decentralized code comments, inline reviews, and discussions
7#[derive(Parser)]
8#[command(name = "git-notes", version, about, long_about = None)]
9pub struct Cli {
10    #[command(subcommand)]
11    pub command: Commands,
12}
13
14#[derive(Subcommand)]
15pub enum Commands {
16    /// Add a new note [alias: a]
17    #[command(alias = "a")]
18    Add(commands::add::AddArgs),
19
20    /// Reply to an existing note thread [alias: r]
21    #[command(alias = "r")]
22    Reply(commands::reply::ReplyArgs),
23
24    /// List notes [aliases: l, ls]
25    #[command(alias = "l", alias = "ls")]
26    List(commands::list::ListArgs),
27
28    /// Show a specific note or thread [alias: s]
29    #[command(alias = "s")]
30    Show(commands::show::ShowArgs),
31
32    /// Sync notes with remote [aliases: push, pull]
33    #[command(alias = "push", alias = "pull")]
34    Sync(commands::sync::SyncArgs),
35
36    /// Resolve a note [aliases: ok, close]
37    #[command(alias = "ok", alias = "close")]
38    Resolve(commands::resolve::ResolveArgs),
39
40    /// Export notes [alias: exp]
41    #[command(alias = "exp")]
42    Export(commands::export::ExportArgs),
43
44    /// Check repository health and configuration [alias: doc]
45    #[command(alias = "doc")]
46    Doctor,
47
48    /// View git blame with inline notes [alias: b]
49    #[command(alias = "b")]
50    Blame(commands::blame::BlameArgs),
51
52    /// Import review comments from a GitHub Pull Request [alias: pr]
53    #[command(alias = "pr")]
54    ImportPr(commands::import_pr::ImportPrArgs),
55
56    /// AI-powered summary of open discussion threads (Gemini) [alias: sum]
57    #[command(alias = "sum")]
58    Summarize(commands::summarize::SummarizeArgs),
59
60    /// Setup git hooks and remote tracking refspec in 1 second [alias: i]
61    #[command(alias = "i")]
62    Init,
63
64    /// Manage git auto-sync hooks
65    Hook(commands::hook::HookArgs),
66
67    /// View diff with inline notes attached to hunks [alias: d]
68    #[command(alias = "d")]
69    Diff(commands::diff::DiffArgs),
70
71    /// View and customize quickies, CLI abbreviations, and keyboard shortcuts [aliases: shortcut, keys, quickies]
72    #[command(alias = "shortcut", alias = "keys", alias = "quickies")]
73    Shortcuts(commands::shortcuts::ShortcutsArgs),
74
75    /// Generate shell completions
76    Completions(commands::completions::CompletionsArgs),
77}
78
79pub fn run_cli() -> anyhow::Result<()> {
80    tracing_subscriber::fmt()
81        .with_env_filter(EnvFilter::from_default_env())
82        .init();
83
84    let mut profile = commands::learning::UserBehaviorProfile::load();
85    let cli = Cli::parse();
86
87    let result = match &cli.command {
88        Commands::Add(args) => {
89            profile.record_interaction("add", Some(&args.file), Some(&args.namespace));
90            commands::add::run(args)
91        }
92        Commands::Reply(args) => {
93            profile.record_interaction("reply", None, None);
94            commands::reply::run(args)
95        }
96        Commands::List(args) => {
97            profile.record_interaction("list", args.file.as_deref(), args.namespace.as_deref());
98            commands::list::run(args)
99        }
100        Commands::Show(args) => {
101            profile.record_interaction("show", None, None);
102            commands::show::run(args)
103        }
104        Commands::Sync(args) => {
105            profile.record_interaction("sync", None, None);
106            commands::sync::run(args)
107        }
108        Commands::Resolve(args) => {
109            profile.record_interaction("resolve", None, None);
110            commands::resolve::run(args)
111        }
112        Commands::Export(args) => {
113            profile.record_interaction("export", None, None);
114            commands::export::run(args)
115        }
116        Commands::Doctor => {
117            profile.record_interaction("doctor", None, None);
118            commands::doctor::run()
119        }
120        Commands::Blame(args) => {
121            profile.record_interaction("blame", Some(&args.file), Some(&args.namespace));
122            commands::blame::run(args)
123        }
124        Commands::ImportPr(args) => {
125            profile.record_interaction("import-pr", None, Some(&args.namespace));
126            commands::import_pr::run(args)
127        }
128        Commands::Summarize(args) => {
129            profile.record_interaction("summarize", None, Some(&args.namespace));
130            commands::summarize::run(args)
131        }
132        Commands::Init => {
133            profile.record_interaction("init", None, None);
134            commands::init::run()
135        }
136        Commands::Hook(args) => {
137            profile.record_interaction("hook", None, None);
138            commands::hook::run(args)
139        }
140        Commands::Diff(args) => {
141            profile.record_interaction("diff", None, Some(&args.namespace));
142            commands::diff::run(args)
143        }
144        Commands::Shortcuts(args) => {
145            profile.record_interaction("shortcuts", None, None);
146            commands::shortcuts::run(args)
147        }
148        Commands::Completions(args) => commands::completions::run(args),
149    };
150
151    if let Some(tip) = profile.suggest_next_action(None) {
152        println!("{}", tip);
153    }
154
155    result
156}