fix(clap_mangen): Use value_names for positionals

This commit is contained in:
ducaale 2022-03-28 20:42:56 +01:00
parent 731d18f300
commit fbd33891b4

View file

@ -61,7 +61,11 @@ pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) {
for arg in cmd.get_positionals() { for arg in cmd.get_positionals() {
let (lhs, rhs) = option_markers(arg); let (lhs, rhs) = option_markers(arg);
line.push(roman(lhs)); line.push(roman(lhs));
line.push(italic(arg.get_id())); if let Some(value) = arg.get_value_names() {
line.push(bold(value.join(" ")));
} else {
line.push(bold(arg.get_id()));
}
line.push(roman(rhs)); line.push(roman(rhs));
line.push(roman(" ")); line.push(roman(" "));
} }
@ -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(); let items: Vec<_> = cmd.get_arguments().filter(|i| !i.is_hide_set()).collect();
for opt in items.iter().filter(|a| !a.is_positional()) { for opt in items.iter().filter(|a| !a.is_positional()) {
let mut body = vec![];
let mut header = match (opt.get_short(), opt.get_long()) { let mut header = match (opt.get_short(), opt.get_long()) {
(Some(short), Some(long)) => { (Some(short), Some(long)) => {
vec![short_option(short), roman(", "), long_option(long)] vec![short_option(short), roman(", "), long_option(long)]
@ -105,6 +107,7 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
header.push(roman(&defs)); header.push(roman(&defs));
} }
let mut body = vec![];
if let Some(help) = opt.get_long_help().or_else(|| opt.get_help()) { if let Some(help) = opt.get_long_help().or_else(|| opt.get_help()) {
body.push(roman(help)); body.push(roman(help));
} }
@ -119,17 +122,21 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
} }
for pos in items.iter().filter(|a| a.is_positional()) { for pos in items.iter().filter(|a| a.is_positional()) {
let mut header = vec![];
let (lhs, rhs) = option_markers(pos); let (lhs, rhs) = option_markers(pos);
let name = format!("{}{}{}", lhs, pos.get_id(), rhs); header.push(roman(lhs));
if let Some(value) = pos.get_value_names() {
let mut header = vec![bold(&name)]; header.push(bold(value.join(" ")));
} else {
let mut body = vec![]; header.push(bold(pos.get_id()));
};
header.push(roman(rhs));
if let Some(defs) = option_default_values(pos) { if let Some(defs) = option_default_values(pos) {
header.push(roman(&format!(" {}", defs))); header.push(roman(&format!(" {}", defs)));
} }
let mut body = vec![];
if let Some(help) = pos.get_long_help().or_else(|| pos.get_help()) { if let Some(help) = pos.get_long_help().or_else(|| pos.get_help()) {
body.push(roman(&help.to_string())); body.push(roman(&help.to_string()));
} }
@ -139,6 +146,7 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
} }
roff.control("TP", []); roff.control("TP", []);
roff.text(header);
roff.text(body); roff.text(body);
} }
} }