mirror of
https://github.com/clap-rs/clap
synced 2025-01-05 17:28:42 +00:00
refactor: Prepare for deferring graph creation
This commit is contained in:
parent
54c2f0df05
commit
b994789ee6
2 changed files with 19 additions and 12 deletions
|
@ -23,6 +23,7 @@ use crate::error::Result as ClapResult;
|
||||||
use crate::mkeymap::MKeyMap;
|
use crate::mkeymap::MKeyMap;
|
||||||
use crate::output::{fmt::Colorizer, Help, HelpWriter, Usage};
|
use crate::output::{fmt::Colorizer, Help, HelpWriter, Usage};
|
||||||
use crate::parse::{ArgMatcher, ArgMatches, Input, Parser};
|
use crate::parse::{ArgMatcher, ArgMatches, Input, Parser};
|
||||||
|
use crate::util::ChildGraph;
|
||||||
use crate::util::{color::ColorChoice, Id, Key};
|
use crate::util::{color::ColorChoice, Id, Key};
|
||||||
use crate::{Error, INTERNAL_ERROR_MSG};
|
use crate::{Error, INTERNAL_ERROR_MSG};
|
||||||
|
|
||||||
|
@ -4444,6 +4445,23 @@ impl<'help> App<'help> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn required_graph(&self) -> ChildGraph<Id> {
|
||||||
|
let mut reqs = ChildGraph::with_capacity(5);
|
||||||
|
for a in self.args.args().filter(|a| a.is_required_set()) {
|
||||||
|
reqs.insert(a.id.clone());
|
||||||
|
}
|
||||||
|
for group in &self.groups {
|
||||||
|
if group.required {
|
||||||
|
let idx = reqs.insert(group.id.clone());
|
||||||
|
for a in &group.requires {
|
||||||
|
reqs.insert_child(idx, a.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reqs
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn unroll_args_in_group(&self, group: &Id) -> Vec<Id> {
|
pub(crate) fn unroll_args_in_group(&self, group: &Id) -> Vec<Id> {
|
||||||
debug!("App::unroll_args_in_group: group={:?}", group);
|
debug!("App::unroll_args_in_group: group={:?}", group);
|
||||||
let mut g_vec = vec![group];
|
let mut g_vec = vec![group];
|
||||||
|
|
|
@ -37,18 +37,7 @@ pub(crate) struct Parser<'help, 'app> {
|
||||||
// Initializing Methods
|
// Initializing Methods
|
||||||
impl<'help, 'app> Parser<'help, 'app> {
|
impl<'help, 'app> Parser<'help, 'app> {
|
||||||
pub(crate) fn new(app: &'app mut App<'help>) -> Self {
|
pub(crate) fn new(app: &'app mut App<'help>) -> Self {
|
||||||
let mut reqs = ChildGraph::with_capacity(5);
|
let reqs = app.required_graph();
|
||||||
for a in app.args.args().filter(|a| a.is_required_set()) {
|
|
||||||
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 {
|
Parser {
|
||||||
app,
|
app,
|
||||||
|
|
Loading…
Reference in a new issue