Skip to content

Commit

Permalink
Group commands under dedicated heading in --help output (#2302)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Aug 5, 2024
1 parent 915619f commit f9c2479
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
47 changes: 32 additions & 15 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ mod cmd {

pub(crate) const ARGLESS: &[&str] =
&[CHANGELOG, DUMP, EDIT, FORMAT, INIT, MAN, SUMMARY, VARIABLES];

pub(crate) const HEADING: &str = "Commands";
}

mod arg {
Expand Down Expand Up @@ -384,7 +386,8 @@ impl Config {
Arg::new(cmd::CHANGELOG)
.long("changelog")
.action(ArgAction::SetTrue)
.help("Print changelog"),
.help("Print changelog")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::CHOOSE)
Expand All @@ -393,7 +396,8 @@ impl Config {
.help(
"Select one or more recipes to run using a binary chooser. If `--chooser` is not \
passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`",
),
)
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::COMMAND)
Expand All @@ -406,7 +410,8 @@ impl Config {
.help(
"Run an arbitrary command with the working directory, `.env`, overrides, and exports \
set",
),
)
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::COMPLETIONS)
Expand All @@ -415,20 +420,23 @@ impl Config {
.value_name("SHELL")
.value_parser(value_parser!(completions::Shell))
.ignore_case(true)
.help("Print shell completion script for <SHELL>"),
.help("Print shell completion script for <SHELL>")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::DUMP)
.long("dump")
.action(ArgAction::SetTrue)
.help("Print justfile"),
.help("Print justfile")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::EDIT)
.short('e')
.long("edit")
.action(ArgAction::SetTrue)
.help("Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`"),
.help("Edit justfile with editor given by $VISUAL or $EDITOR, falling back to `vim`")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::EVALUATE)
Expand All @@ -438,27 +446,31 @@ impl Config {
.help(
"Evaluate and print all variables. If a variable name is given as an argument, only \
print that variable's value.",
),
)
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::FORMAT)
.long("fmt")
.alias("format")
.action(ArgAction::SetTrue)
.help("Format and overwrite justfile"),
.help("Format and overwrite justfile")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::GROUPS)
.long("groups")
.action(ArgAction::SetTrue)
.help("List recipe groups"),
.help("List recipe groups")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::INIT)
.long("init")
.alias("initialize")
.action(ArgAction::SetTrue)
.help("Initialize new justfile in project root"),
.help("Initialize new justfile in project root")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::LIST)
Expand All @@ -468,13 +480,15 @@ impl Config {
.value_name("PATH")
.action(ArgAction::Set)
.conflicts_with(arg::ARGUMENTS)
.help("List available recipes"),
.help("List available recipes")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::MAN)
.long("man")
.action(ArgAction::SetTrue)
.help("Print man page"),
.help("Print man page")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::SHOW)
Expand All @@ -484,19 +498,22 @@ impl Config {
.action(ArgAction::Set)
.value_name("PATH")
.conflicts_with(arg::ARGUMENTS)
.help("Show recipe at <PATH>"),
.help("Show recipe at <PATH>")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::SUMMARY)
.long("summary")
.action(ArgAction::SetTrue)
.help("List names of available recipes"),
.help("List names of available recipes")
.help_heading(cmd::HEADING),
)
.arg(
Arg::new(cmd::VARIABLES)
.long("variables")
.action(ArgAction::SetTrue)
.help("List names of variables"),
.help("List names of variables")
.help_heading(cmd::HEADING),
)
.group(ArgGroup::new("SUBCOMMAND").args(cmd::ALL))
.arg(
Expand Down
5 changes: 3 additions & 2 deletions tests/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ fn replacements() {
.unwrap();
assert!(
output.status.success(),
"shell completion generation for {shell} failed: {}",
output.status
"shell completion generation for {shell} failed: {}\n{}",
output.status,
String::from_utf8_lossy(&output.stderr),
);
}
}

0 comments on commit f9c2479

Please sign in to comment.