Skip to content

Commit

Permalink
fix(usage): Track all required
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 1, 2022
1 parent 232c17e commit 05f8151
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/build/app/mod.rs
Expand Up @@ -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(&[])
}
}
Expand Down
23 changes: 8 additions & 15 deletions src/parse/parser.rs
Expand Up @@ -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,
Expand All @@ -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")]
Expand All @@ -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;
Expand Down

0 comments on commit 05f8151

Please sign in to comment.