1+ use crate :: forge:: review;
2+ use crate :: { base, branch, forge} ;
13use 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" ) ) ]
77pub struct Args {
@@ -11,6 +11,11 @@ pub struct Args {
1111 /// Run as if gitbutler-cli was started in PATH instead of the current working directory.
1212 #[ clap( short = 'C' , long, default_value = "." , value_name = "PATH" ) ]
1313 pub current_dir : PathBuf ,
14+ /// Explicitly control how output should be formatted.
15+ ///
16+ /// If unset and from a terminal, it defaults to human output, when redirected it's for shells.
17+ #[ clap( long, short = 'f' , env = "BUT_OUTPUT_FORMAT" , conflicts_with = "json" ) ]
18+ pub format : Option < OutputFormat > ,
1419 /// Whether to use JSON output format.
1520 #[ clap( long, short = 'j' , global = true ) ]
1621 pub json : bool ,
@@ -84,9 +89,9 @@ For examples see `but rub --help`."
8489 repo : bool ,
8590 } ,
8691 /// Commands for managing the base.
87- Base ( crate :: base:: Platform ) ,
92+ Base ( base:: Platform ) ,
8893 /// Commands for managing branches.
89- Branch ( crate :: branch:: Platform ) ,
94+ Branch ( branch:: Platform ) ,
9095 /// Commands for managing worktrees.
9196 #[ clap( hide = true ) ]
9297 Worktree ( crate :: worktree:: Platform ) ,
@@ -198,35 +203,82 @@ For examples see `but rub --help`."
198203 } ,
199204}
200205
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+ }
265+ }
266+
201267#[ derive( Debug , Clone , Copy , clap:: ValueEnum , Default ) ]
202268pub enum CommandName {
203- #[ clap( alias = "log" ) ]
204269 Log ,
205- #[ clap( alias = "absorb" ) ]
206270 Absorb ,
207- #[ clap( alias = "st" ) ]
208271 Status ,
209- #[ clap( alias = "stf" , hide = true ) ]
210272 Stf ,
211- #[ clap( alias = "rub" ) ]
212273 Rub ,
213- #[ clap( alias = "commit" ) ]
214274 Commit ,
215- #[ clap( alias = "push" ) ]
216275 Push ,
217- #[ clap( alias = "new" ) ]
218276 New ,
219- #[ clap( alias = "describe" ) ]
220277 Describe ,
221- #[ clap( alias = "oplog" ) ]
222278 Oplog ,
223- #[ clap( alias = "restore" ) ]
224279 Restore ,
225- #[ clap( alias = "undo" ) ]
226280 Undo ,
227- #[ clap( alias = "snapshot" ) ]
228281 Snapshot ,
229- #[ clap( alias = "gui" ) ]
230282 Gui ,
231283 BaseCheck ,
232284 BaseUpdate ,
@@ -235,40 +287,10 @@ pub enum CommandName {
235287 BranchList ,
236288 BranchUnapply ,
237289 BranchApply ,
238- #[ clap(
239- alias = "claude-pre-tool" ,
240- alias = "claudepretool" ,
241- alias = "claudePreTool" ,
242- alias = "ClaudePreTool"
243- ) ]
244290 ClaudePreTool ,
245- #[ clap(
246- alias = "claude-post-tool" ,
247- alias = "claudeposttool" ,
248- alias = "claudePostTool" ,
249- alias = "ClaudePostTool"
250- ) ]
251291 ClaudePostTool ,
252- #[ clap(
253- alias = "claude-stop" ,
254- alias = "claudestop" ,
255- alias = "claudeStop" ,
256- alias = "ClaudeStop"
257- ) ]
258292 ClaudeStop ,
259- #[ clap(
260- alias = "cursor-after-edit" ,
261- alias = "cursorafteredit" ,
262- alias = "cursorAfterEdit" ,
263- alias = "CursorAfterEdit"
264- ) ]
265293 CursorAfterEdit ,
266- #[ clap(
267- alias = "cursor-stop" ,
268- alias = "cursorstop" ,
269- alias = "cursorStop" ,
270- alias = "CursorStop"
271- ) ]
272294 CursorStop ,
273295 Worktree ,
274296 Mark ,
@@ -283,6 +305,18 @@ pub enum CommandName {
283305 Unknown ,
284306}
285307
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+
286320pub mod actions {
287321 #[ derive( Debug , clap:: Parser ) ]
288322 pub struct Platform {
0 commit comments