1use clap::{Parser, Subcommand};
2use tracing_subscriber::EnvFilter;
3
4pub mod commands;
5
6#[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 #[command(alias = "a")]
18 Add(commands::add::AddArgs),
19
20 #[command(alias = "r")]
22 Reply(commands::reply::ReplyArgs),
23
24 #[command(alias = "l", alias = "ls")]
26 List(commands::list::ListArgs),
27
28 #[command(alias = "s")]
30 Show(commands::show::ShowArgs),
31
32 #[command(alias = "push", alias = "pull")]
34 Sync(commands::sync::SyncArgs),
35
36 #[command(alias = "ok", alias = "close")]
38 Resolve(commands::resolve::ResolveArgs),
39
40 #[command(alias = "exp")]
42 Export(commands::export::ExportArgs),
43
44 #[command(alias = "doc")]
46 Doctor,
47
48 #[command(alias = "b")]
50 Blame(commands::blame::BlameArgs),
51
52 #[command(alias = "pr")]
54 ImportPr(commands::import_pr::ImportPrArgs),
55
56 #[command(alias = "sum")]
58 Summarize(commands::summarize::SummarizeArgs),
59
60 #[command(alias = "i")]
62 Init,
63
64 Hook(commands::hook::HookArgs),
66
67 #[command(alias = "d")]
69 Diff(commands::diff::DiffArgs),
70
71 Completions(commands::completions::CompletionsArgs),
73}
74
75pub fn run_cli() -> anyhow::Result<()> {
76 tracing_subscriber::fmt()
77 .with_env_filter(EnvFilter::from_default_env())
78 .init();
79
80 let mut profile = commands::learning::UserBehaviorProfile::load();
81 let cli = Cli::parse();
82
83 let result = match &cli.command {
84 Commands::Add(args) => {
85 profile.record_interaction("add", Some(&args.file), Some(&args.namespace));
86 commands::add::run(args)
87 }
88 Commands::Reply(args) => {
89 profile.record_interaction("reply", None, None);
90 commands::reply::run(args)
91 }
92 Commands::List(args) => {
93 profile.record_interaction("list", args.file.as_deref(), args.namespace.as_deref());
94 commands::list::run(args)
95 }
96 Commands::Show(args) => {
97 profile.record_interaction("show", None, None);
98 commands::show::run(args)
99 }
100 Commands::Sync(args) => {
101 profile.record_interaction("sync", None, None);
102 commands::sync::run(args)
103 }
104 Commands::Resolve(args) => {
105 profile.record_interaction("resolve", None, None);
106 commands::resolve::run(args)
107 }
108 Commands::Export(args) => {
109 profile.record_interaction("export", None, None);
110 commands::export::run(args)
111 }
112 Commands::Doctor => {
113 profile.record_interaction("doctor", None, None);
114 commands::doctor::run()
115 }
116 Commands::Blame(args) => {
117 profile.record_interaction("blame", Some(&args.file), Some(&args.namespace));
118 commands::blame::run(args)
119 }
120 Commands::ImportPr(args) => {
121 profile.record_interaction("import-pr", None, Some(&args.namespace));
122 commands::import_pr::run(args)
123 }
124 Commands::Summarize(args) => {
125 profile.record_interaction("summarize", None, Some(&args.namespace));
126 commands::summarize::run(args)
127 }
128 Commands::Init => {
129 profile.record_interaction("init", None, None);
130 commands::init::run()
131 }
132 Commands::Hook(args) => {
133 profile.record_interaction("hook", None, None);
134 commands::hook::run(args)
135 }
136 Commands::Diff(args) => {
137 profile.record_interaction("diff", None, Some(&args.namespace));
138 commands::diff::run(args)
139 }
140 Commands::Completions(args) => commands::completions::run(args),
141 };
142
143 if let Some(tip) = profile.suggest_next_action(None) {
144 println!("{}", tip);
145 }
146
147 result
148}