Skip to content

Commit f2fa939

Browse files
authored
Merge pull request #10469 from gitbutlerapp/sc-but-docs
sc-but-docs-st-stf
2 parents e1eeb8b + 664eca5 commit f2fa939

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

crates/but/src/args.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ pub enum Subcommands {
1919
/// Provides an overview of the Workspace commit graph.
2020
Log,
2121
/// Overview of the uncommitted changes in the repository.
22+
#[clap(alias = "st")]
2223
Status {
2324
/// Determines whether the committed files should be shown as well.
2425
#[clap(short = 'f', alias = "files", default_value_t = false)]
2526
show_files: bool,
2627
},
2728
/// Overview of the uncommitted changes in the repository with files shown.
2829
/// Equivalent to `but status --files`.
30+
#[clap(hide = true)]
2931
Stf,
3032

3133
/// Combines two entities together to perform an operation.

crates/but/src/main.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use anyhow::{Context, Result};
33
mod args;
44
use args::{Args, CommandName, Subcommands, actions, claude, cursor};
55
use but_settings::AppSettings;
6+
use colored::Colorize;
67
use metrics::{Event, Metrics, Props, metrics_if_configured};
78

89
use but_claude::hooks::OutputAsJson;
@@ -24,6 +25,14 @@ mod status;
2425

2526
#[tokio::main]
2627
async fn main() -> Result<()> {
28+
// Check if help is requested with no subcommand
29+
if std::env::args().len() == 1
30+
|| std::env::args().any(|arg| arg == "--help" || arg == "-h") && std::env::args().len() == 2
31+
{
32+
print_grouped_help();
33+
return Ok(());
34+
}
35+
2736
let args: Args = clap::Parser::parse();
2837
let app_settings = AppSettings::load_from_default_path_creating()?;
2938

@@ -209,3 +218,68 @@ where
209218
props.insert("error", error);
210219
props
211220
}
221+
222+
fn print_grouped_help() {
223+
use clap::CommandFactory;
224+
use std::collections::HashSet;
225+
226+
let cmd = Args::command();
227+
let subcommands: Vec<_> = cmd.get_subcommands().collect();
228+
229+
// Define command groupings and their order (excluding MISC)
230+
let groups = [
231+
("Inspection".yellow(), vec!["log", "status"]),
232+
(
233+
"Stack Operation".yellow(),
234+
vec!["commit", "rub", "new", "describe", "branch"],
235+
),
236+
(
237+
"Operation History".yellow(),
238+
vec!["oplog", "undo", "restore"],
239+
),
240+
];
241+
242+
println!("{}", "The GitButler CLI change control system".red());
243+
println!();
244+
println!("Usage: but [OPTIONS] <COMMAND>");
245+
println!();
246+
247+
// Keep track of which commands we've already printed
248+
let mut printed_commands = HashSet::new();
249+
250+
// Print grouped commands
251+
for (group_name, command_names) in &groups {
252+
println!("{group_name}:");
253+
for cmd_name in command_names {
254+
if let Some(subcmd) = subcommands.iter().find(|c| c.get_name() == *cmd_name) {
255+
let about = subcmd.get_about().unwrap_or_default();
256+
println!(" {:<10}{about}", cmd_name.green());
257+
printed_commands.insert(cmd_name.to_string());
258+
}
259+
}
260+
println!();
261+
}
262+
263+
// Collect any remaining commands not in the explicit groups
264+
let misc_commands: Vec<_> = subcommands
265+
.iter()
266+
.filter(|subcmd| !printed_commands.contains(subcmd.get_name()) && !subcmd.is_hide_set())
267+
.collect();
268+
269+
// Print MISC section if there are any ungrouped commands
270+
if !misc_commands.is_empty() {
271+
println!("{}:", "Other Commands".yellow());
272+
for subcmd in misc_commands {
273+
let about = subcmd.get_about().unwrap_or_default();
274+
println!(" {:<10}{}", subcmd.get_name().green(), about);
275+
}
276+
println!();
277+
}
278+
279+
println!("{}:", "Options".yellow());
280+
println!(
281+
" -C, --current-dir <PATH> Run as if but was started in PATH instead of the current working directory [default: .]"
282+
);
283+
println!(" -j, --json Whether to use JSON output format");
284+
println!(" -h, --help Print help");
285+
}

0 commit comments

Comments
 (0)