Skip to content

Commit dbda345

Browse files
committed
More convenient metrics handling and bringing JSON printing and bringing it all together.
1 parent 506f89f commit dbda345

File tree

4 files changed

+141
-123
lines changed

4 files changed

+141
-123
lines changed

crates/but/src/args.rs

Lines changed: 75 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use crate::forge::review;
2+
use crate::{base, branch, forge};
13
use std::path::PathBuf;
24

3-
use crate::forge;
4-
55
#[derive(Debug, clap::Parser)]
66
#[clap(name = "but", about = "A GitButler CLI tool", version = option_env!("GIX_VERSION"))]
77
pub struct Args {
@@ -89,9 +89,9 @@ For examples see `but rub --help`."
8989
repo: bool,
9090
},
9191
/// Commands for managing the base.
92-
Base(crate::base::Platform),
92+
Base(base::Platform),
9393
/// Commands for managing branches.
94-
Branch(crate::branch::Platform),
94+
Branch(branch::Platform),
9595
/// Commands for managing worktrees.
9696
#[clap(hide = true)]
9797
Worktree(crate::worktree::Platform),
@@ -203,47 +203,82 @@ For examples see `but rub --help`."
203203
},
204204
}
205205

206-
/// How to format the output.
207-
#[derive(Debug, Clone, Copy, clap::ValueEnum, Default)]
208-
pub enum OutputFormat {
209-
/// Produce verbose output for human consumption.
210-
#[default]
211-
Human,
212-
/// The output is optimised for variable assignment in shells.
213-
Shell,
214-
/// Output detailed information as JSON for tool consumption.
215-
Json,
206+
impl Subcommands {
207+
pub fn to_metrics_command(&self) -> CommandName {
208+
use CommandName::*;
209+
match self {
210+
Subcommands::Log => Log,
211+
Subcommands::Status { .. } => Status,
212+
Subcommands::Stf { .. } => Stf,
213+
Subcommands::Rub { .. } => Rub,
214+
Subcommands::Base(base::Platform { cmd }) => match cmd {
215+
base::Subcommands::Update => BaseUpdate,
216+
base::Subcommands::Check => BaseCheck,
217+
},
218+
Subcommands::Branch(branch::Platform { cmd }) => match cmd {
219+
None | Some(branch::Subcommands::List { .. }) => BranchList,
220+
Some(branch::Subcommands::New { .. }) => BranchNew,
221+
Some(branch::Subcommands::Delete { .. }) => BranchDelete,
222+
Some(branch::Subcommands::Unapply { .. }) => BranchUnapply,
223+
Some(branch::Subcommands::Apply { .. }) => BranchApply,
224+
},
225+
Subcommands::Worktree(crate::worktree::Platform { cmd: _ }) => Worktree,
226+
Subcommands::Mark { .. } => Mark,
227+
Subcommands::Unmark => Unmark,
228+
Subcommands::Gui => Gui,
229+
Subcommands::Commit { .. } => Commit,
230+
Subcommands::Push(_) => Push,
231+
Subcommands::New { .. } => New,
232+
Subcommands::Describe { .. } => Describe,
233+
Subcommands::Oplog { .. } => Oplog,
234+
Subcommands::Restore { .. } => Restore,
235+
Subcommands::Undo => Undo,
236+
Subcommands::Snapshot { .. } => Snapshot,
237+
Subcommands::Claude(claude::Platform { cmd }) => match cmd {
238+
claude::Subcommands::PreTool => ClaudePreTool,
239+
claude::Subcommands::PostTool => ClaudePostTool,
240+
claude::Subcommands::Stop => ClaudeStop,
241+
claude::Subcommands::Last { .. }
242+
| claude::Subcommands::PermissionPromptMcp { .. } => Unknown,
243+
},
244+
Subcommands::Cursor(cursor::Platform { cmd }) => match cmd {
245+
cursor::Subcommands::AfterEdit => CursorAfterEdit,
246+
cursor::Subcommands::Stop { .. } => CursorStop,
247+
},
248+
Subcommands::Forge(forge::integration::Platform { cmd }) => match cmd {
249+
forge::integration::Subcommands::Auth => ForgeAuth,
250+
forge::integration::Subcommands::Forget { .. } => ForgeForget,
251+
forge::integration::Subcommands::ListUsers => ForgeListUsers,
252+
},
253+
Subcommands::Review(review::Platform { cmd }) => match cmd {
254+
review::Subcommands::Publish { .. } => PublishReview,
255+
review::Subcommands::Template { .. } => ReviewTemplate,
256+
},
257+
Subcommands::Completions { .. } => Completions,
258+
Subcommands::Absorb { .. } => Absorb,
259+
Subcommands::Metrics { .. }
260+
| Subcommands::Actions(_)
261+
| Subcommands::Mcp { .. }
262+
| Subcommands::Init { .. } => Unknown,
263+
}
264+
}
216265
}
217266

218267
#[derive(Debug, Clone, Copy, clap::ValueEnum, Default)]
219268
pub enum CommandName {
220-
#[clap(alias = "log")]
221269
Log,
222-
#[clap(alias = "absorb")]
223270
Absorb,
224-
#[clap(alias = "st")]
225271
Status,
226-
#[clap(alias = "stf", hide = true)]
227272
Stf,
228-
#[clap(alias = "rub")]
229273
Rub,
230-
#[clap(alias = "commit")]
231274
Commit,
232-
#[clap(alias = "push")]
233275
Push,
234-
#[clap(alias = "new")]
235276
New,
236-
#[clap(alias = "describe")]
237277
Describe,
238-
#[clap(alias = "oplog")]
239278
Oplog,
240-
#[clap(alias = "restore")]
241279
Restore,
242-
#[clap(alias = "undo")]
243280
Undo,
244-
#[clap(alias = "snapshot")]
245281
Snapshot,
246-
#[clap(alias = "gui")]
247282
Gui,
248283
BaseCheck,
249284
BaseUpdate,
@@ -252,40 +287,10 @@ pub enum CommandName {
252287
BranchList,
253288
BranchUnapply,
254289
BranchApply,
255-
#[clap(
256-
alias = "claude-pre-tool",
257-
alias = "claudepretool",
258-
alias = "claudePreTool",
259-
alias = "ClaudePreTool"
260-
)]
261290
ClaudePreTool,
262-
#[clap(
263-
alias = "claude-post-tool",
264-
alias = "claudeposttool",
265-
alias = "claudePostTool",
266-
alias = "ClaudePostTool"
267-
)]
268291
ClaudePostTool,
269-
#[clap(
270-
alias = "claude-stop",
271-
alias = "claudestop",
272-
alias = "claudeStop",
273-
alias = "ClaudeStop"
274-
)]
275292
ClaudeStop,
276-
#[clap(
277-
alias = "cursor-after-edit",
278-
alias = "cursorafteredit",
279-
alias = "cursorAfterEdit",
280-
alias = "CursorAfterEdit"
281-
)]
282293
CursorAfterEdit,
283-
#[clap(
284-
alias = "cursor-stop",
285-
alias = "cursorstop",
286-
alias = "cursorStop",
287-
alias = "CursorStop"
288-
)]
289294
CursorStop,
290295
Worktree,
291296
Mark,
@@ -300,6 +305,18 @@ pub enum CommandName {
300305
Unknown,
301306
}
302307

308+
/// How to format the output.
309+
#[derive(Debug, Clone, Copy, clap::ValueEnum, Default)]
310+
pub enum OutputFormat {
311+
/// Produce verbose output for human consumption.
312+
#[default]
313+
Human,
314+
/// The output is optimised for variable assignment in shells.
315+
Shell,
316+
/// Output detailed information as JSON for tool consumption.
317+
Json,
318+
}
319+
303320
pub mod actions {
304321
#[derive(Debug, clap::Parser)]
305322
pub struct Platform {

0 commit comments

Comments
 (0)