fix(usage): Track all required

This commit is contained in:
Ed Page 2022-02-01 13:38:23 -06:00
parent 232c17ebc4
commit 05f8151d3d
2 changed files with 9 additions and 17 deletions

View file

@ -824,8 +824,7 @@ impl<'help> App<'help> {
// before parsing incase we run into a subcommand
self._build();
let mut parser = Parser::new(self);
parser._build();
let parser = Parser::new(self);
Usage::new(&parser.app, &parser.required).create_usage_with_title(&[])
}
}

View file

@ -48,6 +48,14 @@ impl<'help, 'app> Parser<'help, 'app> {
{
reqs.insert(a.id.clone());
}
for group in &app.groups {
if group.required {
let idx = reqs.insert(group.id.clone());
for a in &group.requires {
reqs.insert_child(idx, a.clone());
}
}
}
Parser {
app,
@ -60,20 +68,6 @@ impl<'help, 'app> Parser<'help, 'app> {
}
}
// Does all the initializing and prepares the parser
pub(crate) fn _build(&mut self) {
debug!("Parser::_build");
for group in &self.app.groups {
if group.required {
let idx = self.required.insert(group.id.clone());
for a in &group.requires {
self.required.insert_child(idx, a.clone());
}
}
}
}
// Should we color the help?
pub(crate) fn color_help(&self) -> ColorChoice {
#[cfg(feature = "color")]
@ -96,7 +90,6 @@ impl<'help, 'app> Parser<'help, 'app> {
) -> ClapResult<()> {
debug!("Parser::get_matches_with");
// Verify all positional assertions pass
self._build();
let mut subcmd_name: Option<String> = None;
let mut keep_state = false;