Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mangen): Honor the bin_name when rendering manpages #4758

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions clap_mangen/src/render.rs
Expand Up @@ -28,8 +28,14 @@ pub(crate) fn description(roff: &mut Roff, cmd: &clap::Command) {
}
}

fn get_command_name(cmd: &clap::Command) -> &str {
cmd.get_bin_name()
.or_else(|| cmd.get_display_name())
.unwrap_or_else(|| cmd.get_name())
}
Comment on lines +31 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main risk for this is if the user parsed with the Command before calling this, leading it to have a .exe in the root bin name which can cause problems with this approach


pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) {
let mut line = vec![bold(cmd.get_name()), roman(" ")];
let mut line = vec![bold(get_command_name(cmd)), roman(" ")];

for opt in cmd.get_arguments().filter(|i| !i.is_hide_set()) {
let (lhs, rhs) = option_markers(opt);
Expand Down Expand Up @@ -225,12 +231,7 @@ pub(crate) fn subcommands(roff: &mut Roff, cmd: &clap::Command, section: &str) {
for sub in cmd.get_subcommands().filter(|s| !s.is_hide_set()) {
roff.control("TP", []);

let name = format!(
"{}-{}({})",
cmd.get_display_name().unwrap_or_else(|| cmd.get_name()),
sub.get_name(),
section
);
let name = format!("{}-{}({})", get_command_name(cmd), sub.get_name(), section);
roff.text([roman(name)]);

if let Some(about) = sub.get_about().or_else(|| sub.get_long_about()) {
Expand Down
8 changes: 4 additions & 4 deletions clap_mangen/tests/snapshots/sub_subcommand_help.roff
Expand Up @@ -4,16 +4,16 @@
.SH NAME
help /- Print this message or the help of the given subcommand(s)
.SH SYNOPSIS
/fBhelp/fR [/fIsubcommands/fR]
/fBmy/-app help/fR [/fIsubcommands/fR]
.SH DESCRIPTION
Print this message or the help of the given subcommand(s)
.SH SUBCOMMANDS
.TP
my/-app/-help/-test(1)
my/-app help/-test(1)
tests things
.TP
my/-app/-help/-some_cmd(1)
my/-app help/-some_cmd(1)
top level subcommand
.TP
my/-app/-help/-help(1)
my/-app help/-help(1)
Comment on lines +12 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these have - all the way through?

Print this message or the help of the given subcommand(s)