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

Use Arg::value_name() as header for positionals in clap_mangen #3587

Merged
merged 3 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions clap_mangen/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) {
for arg in cmd.get_positionals() {
let (lhs, rhs) = option_markers(arg);
line.push(roman(lhs));
line.push(italic(arg.get_id()));
if let Some(value) = arg.get_value_names() {
line.push(italic(value.join(" ")));
} else {
line.push(italic(arg.get_id()));
}
line.push(roman(rhs));
line.push(roman(" "));
}
Expand All @@ -84,8 +88,6 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
let items: Vec<_> = cmd.get_arguments().filter(|i| !i.is_hide_set()).collect();

for opt in items.iter().filter(|a| !a.is_positional()) {
let mut body = vec![];

let mut header = match (opt.get_short(), opt.get_long()) {
(Some(short), Some(long)) => {
vec![short_option(short), roman(", "), long_option(long)]
Expand All @@ -105,6 +107,7 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
header.push(roman(&defs));
}

let mut body = vec![];
if let Some(help) = opt.get_long_help().or_else(|| opt.get_help()) {
body.push(roman(help));
}
Expand All @@ -119,17 +122,21 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
}

for pos in items.iter().filter(|a| a.is_positional()) {
let mut header = vec![];
let (lhs, rhs) = option_markers(pos);
let name = format!("{}{}{}", lhs, pos.get_id(), rhs);

let mut header = vec![bold(&name)];

let mut body = vec![];
header.push(roman(lhs));
if let Some(value) = pos.get_value_names() {
header.push(italic(value.join(" ")));
} else {
header.push(italic(pos.get_id()));
};
header.push(roman(rhs));

if let Some(defs) = option_default_values(pos) {
header.push(roman(&format!(" {}", defs)));
}

let mut body = vec![];
if let Some(help) = pos.get_long_help().or_else(|| pos.get_help()) {
body.push(roman(&help.to_string()));
}
Expand All @@ -139,6 +146,7 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
}

roff.control("TP", []);
roff.text(header);
roff.text(body);
}
}
Expand Down
1 change: 1 addition & 0 deletions clap_mangen/tests/snapshots/aliases.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cmd flag
/fB/-o/fR, /fB/-/-option/fR
cmd option
.TP
[/fIpositional/fR]

.SH VERSION
v3.0
2 changes: 2 additions & 0 deletions clap_mangen/tests/snapshots/feature_sample.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Print version information
/fB/-c/fR, /fB/-/-config/fR
some config file
.TP
[/fIfile/fR]
some input file
.TP
[/fIchoice/fR]

.SH SUBCOMMANDS
.TP
Expand Down
2 changes: 2 additions & 0 deletions clap_mangen/tests/snapshots/special_commands.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Print version information
/fB/-c/fR, /fB/-/-config/fR
some config file
.TP
[/fIfile/fR]
some input file
.TP
[/fIchoice/fR]

.SH SUBCOMMANDS
.TP
Expand Down
2 changes: 2 additions & 0 deletions clap_mangen/tests/snapshots/sub_subcommands.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Print version information
/fB/-c/fR, /fB/-/-config/fR
some config file
.TP
[/fIfile/fR]
some input file
.TP
[/fIchoice/fR]

.SH SUBCOMMANDS
.TP
Expand Down
1 change: 1 addition & 0 deletions clap_mangen/tests/snapshots/value_hint.bash.roff
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ Print help information
/fB/-/-email/fR

.TP
[/fIcommand_with_args/fR]