-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(mangen): Support flatten_help #5769
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Most of these differences sound unrelated to flattening |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,20 +30,42 @@ pub(crate) fn description(roff: &mut Roff, cmd: &clap::Command) { | |
| } | ||
|
|
||
| pub(crate) fn synopsis(roff: &mut Roff, cmd: &clap::Command) { | ||
| let name = cmd.get_bin_name().unwrap_or_else(|| cmd.get_name()); | ||
| let mut line = usage(cmd, name); | ||
|
|
||
| if cmd.has_subcommands() { | ||
| let (lhs, rhs) = subcommand_markers(cmd); | ||
| line.push(roman(lhs)); | ||
| line.push(italic( | ||
| cmd.get_subcommand_value_name() | ||
| .unwrap_or_else(|| subcommand_heading(cmd)) | ||
| .to_lowercase(), | ||
| )); | ||
| line.push(roman(rhs)); | ||
| let flatten = cmd.is_flatten_help_set(); | ||
| let mut first = true; | ||
| if !cmd.is_subcommand_required_set() || cmd.is_args_conflicts_with_subcommands_set() { | ||
| let mut line = usage(cmd, cmd.get_bin_name().unwrap_or_else(|| cmd.get_name())); | ||
| if cmd.has_subcommands() && !flatten { | ||
| let (lhs, rhs) = subcommand_markers(cmd); | ||
| line.push(roman(lhs)); | ||
| line.push(italic( | ||
| cmd.get_subcommand_value_name() | ||
| .unwrap_or_else(|| subcommand_heading(cmd)) | ||
| .to_lowercase(), | ||
| )); | ||
| line.push(roman(rhs)); | ||
| } | ||
| roff.text(line); | ||
| first = false; | ||
| } | ||
| if flatten { | ||
| let mut ord_v = Vec::new(); | ||
| for subcommand in cmd.get_subcommands() { | ||
| ord_v.push(( | ||
| subcommand.get_display_order(), | ||
| subcommand.get_bin_name().unwrap_or_else(|| cmd.get_name()), | ||
| subcommand, | ||
| )); | ||
| } | ||
|
Comment on lines
+50
to
+58
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't recursive but should be (same with |
||
| ord_v.sort_by(|a, b| (a.0, &a.1).cmp(&(b.0, &b.1))); | ||
| for (_, name, cmd) in ord_v { | ||
| if !first { | ||
| roff.control("br", []); | ||
| } else { | ||
| first = false; | ||
| } | ||
| roff.text(usage(cmd, name)); | ||
| } | ||
| } | ||
| roff.text(line); | ||
| } | ||
|
|
||
| fn usage(cmd: &clap::Command, name: &str) -> Vec<Inline> { | ||
|
|
@@ -222,6 +244,26 @@ pub(crate) fn subcommands(roff: &mut Roff, cmd: &clap::Command, section: &str) { | |
| } | ||
| } | ||
|
|
||
| pub(crate) fn flat_subcommands(roff: &mut Roff, cmd: &clap::Command) { | ||
| for sub in cmd.get_subcommands().filter(|s| !s.is_hide_set()) { | ||
| roff.control("TP", []); | ||
|
|
||
| let mut line = usage(sub, sub.get_name()); | ||
|
|
||
| if let Some(about) = sub.get_long_about().or_else(|| sub.get_about()) { | ||
| line.push(roman("\n")); | ||
| line.push(roman(about.to_string())); | ||
| } | ||
|
|
||
| if let Some(after_help) = sub.get_after_help() { | ||
| line.push(roman("\n")); | ||
| line.push(roman(after_help.to_string())); | ||
| } | ||
|
|
||
| roff.text(line); | ||
| } | ||
| } | ||
|
|
||
| pub(crate) fn version(cmd: &clap::Command) -> String { | ||
| format!( | ||
| "v{}", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.