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", alias = "p2p")]
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 = "imp")]
58 Import(commands::import::ImportArgs),
59
60 #[command(alias = "sum")]
62 Summarize(commands::summarize::SummarizeArgs),
63
64 #[command(alias = "i")]
66 Init,
67
68 Hook(commands::hook::HookArgs),
70
71 #[command(alias = "d")]
73 Diff(commands::diff::DiffArgs),
74
75 #[command(alias = "shortcut", alias = "keys", alias = "quickies")]
77 Shortcuts(commands::shortcuts::ShortcutsArgs),
78
79 Completions(commands::completions::CompletionsArgs),
81
82 #[command(alias = "heal")]
84 RebaseHeal(commands::rebase_heal::RebaseHealArgs),
85}
86
87pub fn run_cli() -> anyhow::Result<()> {
88 tracing_subscriber::fmt()
89 .with_env_filter(EnvFilter::from_default_env())
90 .init();
91
92 let mut profile = commands::learning::UserBehaviorProfile::load();
93 let cli = Cli::parse();
94
95 let result = match &cli.command {
96 Commands::Add(args) => {
97 profile.record_interaction("add", Some(&args.file), Some(&args.namespace));
98 commands::add::run(args)
99 }
100 Commands::Reply(args) => {
101 profile.record_interaction("reply", None, None);
102 commands::reply::run(args)
103 }
104 Commands::List(args) => {
105 profile.record_interaction("list", args.file.as_deref(), args.namespace.as_deref());
106 commands::list::run(args)
107 }
108 Commands::Show(args) => {
109 profile.record_interaction("show", None, None);
110 commands::show::run(args)
111 }
112 Commands::Sync(args) => {
113 profile.record_interaction("sync", None, None);
114 commands::sync::run(args)
115 }
116 Commands::Resolve(args) => {
117 profile.record_interaction("resolve", None, None);
118 commands::resolve::run(args)
119 }
120 Commands::Export(args) => {
121 profile.record_interaction("export", None, None);
122 commands::export::run(args)
123 }
124 Commands::Doctor => {
125 profile.record_interaction("doctor", None, None);
126 commands::doctor::run()
127 }
128 Commands::Blame(args) => {
129 profile.record_interaction("blame", Some(&args.file), Some(&args.namespace));
130 commands::blame::run(args)
131 }
132 Commands::ImportPr(args) => {
133 profile.record_interaction("import-pr", None, Some(&args.namespace));
134 commands::import_pr::run(args)
135 }
136 Commands::Import(args) => {
137 profile.record_interaction("import", None, None);
138 commands::import::run(args)
139 }
140 Commands::Summarize(args) => {
141 profile.record_interaction("summarize", None, Some(&args.namespace));
142 commands::summarize::run(args)
143 }
144 Commands::Init => {
145 profile.record_interaction("init", None, None);
146 commands::init::run()
147 }
148 Commands::Hook(args) => {
149 profile.record_interaction("hook", None, None);
150 commands::hook::run(args)
151 }
152 Commands::Diff(args) => {
153 profile.record_interaction("diff", None, Some(&args.namespace));
154 commands::diff::run(args)
155 }
156 Commands::Shortcuts(args) => {
157 profile.record_interaction("shortcuts", None, None);
158 commands::shortcuts::run(args)
159 }
160 Commands::RebaseHeal(args) => {
161 profile.record_interaction("rebase-heal", None, args.namespace.as_deref());
162 commands::rebase_heal::run(args)
163 }
164 Commands::Completions(args) => commands::completions::run(args),
165 };
166
167 if let Some(tip) = profile.suggest_next_action(None) {
168 println!("{}", tip);
169 }
170
171 result
172}