Merge pull request #4878 from nyurik/dup-mangen

chore: remove dup code in mangen
This commit is contained in:
Ed Page 2023-05-03 19:51:59 -05:00 committed by GitHub
commit 543ad0ce06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
use clap::ArgAction; use clap::{Arg, ArgAction};
use roff::{bold, italic, roman, Inline, Roff}; use roff::{bold, italic, roman, Inline, Roff};
pub(crate) fn subcommand_heading(cmd: &clap::Command) -> &str { pub(crate) fn subcommand_heading(cmd: &clap::Command) -> &str {
@ -122,34 +122,7 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
roff.text(header); roff.text(header);
roff.text(body); roff.text(body);
if let Some((possible_values_text, with_help)) = get_possible_values(opt) { possible_options(roff, opt, arg_help_written);
if arg_help_written {
// It looks nice to have a separation between the help and the values
roff.text([Inline::LineBreak]);
}
if with_help {
roff.text([Inline::LineBreak, italic("Possible values:")]);
// Need to indent twice to get it to look right, because .TP heading indents, but
// that indent doesn't Carry over to the .IP for the bullets. The standard shift
// size is 7 for terminal devices
roff.control("RS", ["14"]);
for line in possible_values_text {
roff.control("IP", ["\\(bu", "2"]);
roff.text([roman(line)]);
}
roff.control("RE", []);
} else {
let possible_value_text: Vec<Inline> = vec![
Inline::LineBreak,
roman("["),
italic("possible values: "),
roman(possible_values_text.join(", ")),
roman("]"),
];
roff.text(possible_value_text);
}
}
if let Some(env) = option_environment(opt) { if let Some(env) = option_environment(opt) {
roff.control("RS", []); roff.control("RS", []);
@ -189,34 +162,38 @@ pub(crate) fn options(roff: &mut Roff, cmd: &clap::Command) {
roff.text(env); roff.text(env);
roff.control("RE", []); roff.control("RE", []);
} }
// If possible options are available
if let Some((possible_values_text, with_help)) = get_possible_values(pos) {
if arg_help_written {
// It looks nice to have a separation between the help and the values
roff.text([Inline::LineBreak]);
}
if with_help {
roff.text([Inline::LineBreak, italic("Possible values:")]);
// Need to indent twice to get it to look right, because .TP heading indents, but possible_options(roff, pos, arg_help_written)
// that indent doesn't Carry over to the .IP for the bullets. The standard shift }
// size is 7 for terminal devices }
roff.control("RS", ["14"]);
for line in possible_values_text { fn possible_options(roff: &mut Roff, arg: &Arg, arg_help_written: bool) {
roff.control("IP", ["\\(bu", "2"]); if let Some((possible_values_text, with_help)) = get_possible_values(arg) {
roff.text([roman(line)]); if arg_help_written {
} // It looks nice to have a separation between the help and the values
roff.control("RE", []); roff.text([Inline::LineBreak]);
} else { }
let possible_value_text: Vec<Inline> = vec![ if with_help {
Inline::LineBreak, roff.text([Inline::LineBreak, italic("Possible values:")]);
roman("["),
italic("possible values: "), // Need to indent twice to get it to look right, because .TP heading indents, but
roman(possible_values_text.join(", ")), // that indent doesn't Carry over to the .IP for the bullets. The standard shift
roman("]"), // size is 7 for terminal devices
]; roff.control("RS", ["14"]);
roff.text(possible_value_text); for line in possible_values_text {
roff.control("IP", ["\\(bu", "2"]);
roff.text([roman(line)]);
} }
roff.control("RE", []);
} else {
let possible_value_text: Vec<Inline> = vec![
Inline::LineBreak,
roman("["),
italic("possible values: "),
roman(possible_values_text.join(", ")),
roman("]"),
];
roff.text(possible_value_text);
} }
} }
} }