mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
Use a different default template when there are no args.
This eliminates extraneous empty lines when there are no user-defined args, the default args are disabled, and `after_help` is set.
This commit is contained in:
parent
de6a5af1b2
commit
85d3daa8c1
3 changed files with 25 additions and 1 deletions
|
@ -2454,6 +2454,11 @@ impl<'help> App<'help> {
|
|||
!self.args.is_empty()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn has_opts(&self) -> bool {
|
||||
self.get_opts_no_heading().count() > 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn has_flags(&self) -> bool {
|
||||
self.get_flags_no_heading().count() > 0
|
||||
|
|
|
@ -82,6 +82,12 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> {
|
|||
{all-args}{after-help}\
|
||||
";
|
||||
|
||||
const DEFAULT_NO_ARGS_TEMPLATE: &'static str = "\
|
||||
{before-help}{bin} {version}\n\
|
||||
{author-with-newline}{about-with-newline}\n\
|
||||
USAGE:\n {usage}{after-help}\
|
||||
";
|
||||
|
||||
/// Create a new `Help` instance.
|
||||
pub(crate) fn new(
|
||||
w: HelpWriter<'writer>,
|
||||
|
@ -124,7 +130,16 @@ impl<'help, 'app, 'parser, 'writer> Help<'help, 'app, 'parser, 'writer> {
|
|||
} else if let Some(tmpl) = self.parser.app.template {
|
||||
self.write_templated_help(tmpl)?;
|
||||
} else {
|
||||
self.write_templated_help(Self::DEFAULT_TEMPLATE)?;
|
||||
let flags = self.parser.has_flags();
|
||||
let pos = self.parser.has_positionals();
|
||||
let opts = self.parser.has_opts();
|
||||
let subcmds = self.parser.has_subcommands();
|
||||
|
||||
if flags || opts || pos || subcmds {
|
||||
self.write_templated_help(Self::DEFAULT_TEMPLATE)?;
|
||||
} else {
|
||||
self.write_templated_help(Self::DEFAULT_NO_ARGS_TEMPLATE)?;
|
||||
}
|
||||
}
|
||||
|
||||
self.none("\n")?;
|
||||
|
|
|
@ -1790,6 +1790,10 @@ impl<'help, 'app> Parser<'help, 'app> {
|
|||
self.app.has_args()
|
||||
}
|
||||
|
||||
pub(crate) fn has_opts(&self) -> bool {
|
||||
self.app.has_opts()
|
||||
}
|
||||
|
||||
pub(crate) fn has_flags(&self) -> bool {
|
||||
self.app.has_flags()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue