mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
Minor redundant logic cleanup
Fix clippy dot fix
This commit is contained in:
parent
8d5a021e1e
commit
8f4c26fc58
2 changed files with 31 additions and 41 deletions
|
@ -365,6 +365,8 @@ impl<'help, 'app, 'parser> Usage<'help, 'app, 'parser> {
|
||||||
// `incl_last`: should we include args that are Arg::Last? (i.e. `prog [foo] -- [last]). We
|
// `incl_last`: should we include args that are Arg::Last? (i.e. `prog [foo] -- [last]). We
|
||||||
// can't do that for required usages being built for subcommands because it would look like:
|
// can't do that for required usages being built for subcommands because it would look like:
|
||||||
// `prog [foo] -- [last] <subcommand>` which is totally wrong.
|
// `prog [foo] -- [last] <subcommand>` which is totally wrong.
|
||||||
|
// TODO: remove the allow clippy when we update the compiler version.
|
||||||
|
#[allow(clippy::needless_collect)]
|
||||||
pub(crate) fn get_required_usage_from(
|
pub(crate) fn get_required_usage_from(
|
||||||
&self,
|
&self,
|
||||||
incls: &[Id],
|
incls: &[Id],
|
||||||
|
@ -419,7 +421,7 @@ impl<'help, 'app, 'parser> Usage<'help, 'app, 'parser> {
|
||||||
|
|
||||||
for p in pmap.values() {
|
for p in pmap.values() {
|
||||||
debug!("Usage::get_required_usage_from:iter:{:?}", p.id);
|
debug!("Usage::get_required_usage_from:iter:{:?}", p.id);
|
||||||
if args_in_groups.is_empty() || !args_in_groups.contains(&p.id) {
|
if !args_in_groups.contains(&p.id) {
|
||||||
ret_val.push(p.to_string());
|
ret_val.push(p.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,25 +356,25 @@ impl<'help, 'app> Parser<'help, 'app> {
|
||||||
|
|
||||||
// Has the user already passed '--'? Meaning only positional args follow
|
// Has the user already passed '--'? Meaning only positional args follow
|
||||||
if !self.is_set(AS::TrailingValues) {
|
if !self.is_set(AS::TrailingValues) {
|
||||||
// Does the arg match a subcommand name, or any of its aliases (if defined)
|
let can_be_subcommand = if self.is_set(AS::SubcommandPrecedenceOverArg) {
|
||||||
match needs_val_of {
|
true
|
||||||
ParseResult::Opt(_) | ParseResult::Pos(_)
|
} else {
|
||||||
if !self.is_set(AS::SubcommandPrecedenceOverArg) => {}
|
match needs_val_of {
|
||||||
_ => {
|
ParseResult::Opt(_) | ParseResult::Pos(_) => false,
|
||||||
let sc_name = self.possible_subcommand(&arg_os);
|
_ => true,
|
||||||
debug!(
|
}
|
||||||
"Parser::get_matches_with: possible_sc={:?}, sc={:?}",
|
};
|
||||||
sc_name.is_some(),
|
|
||||||
sc_name
|
|
||||||
);
|
|
||||||
if let Some(sc_name) = sc_name {
|
|
||||||
if sc_name == "help" && !self.is_set(AS::NoAutoHelp) {
|
|
||||||
self.parse_help_subcommand(remaining_args)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
subcmd_name = Some(sc_name.to_owned());
|
if can_be_subcommand {
|
||||||
break;
|
// Does the arg match a subcommand name, or any of its aliases (if defined)
|
||||||
|
let sc_name = self.possible_subcommand(&arg_os);
|
||||||
|
debug!("Parser::get_matches_with: sc={:?}", sc_name);
|
||||||
|
if let Some(sc_name) = sc_name {
|
||||||
|
if sc_name == "help" && !self.is_set(AS::NoAutoHelp) {
|
||||||
|
self.parse_help_subcommand(remaining_args)?;
|
||||||
}
|
}
|
||||||
|
subcmd_name = Some(sc_name.to_owned());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,31 +477,20 @@ impl<'help, 'app> Parser<'help, 'app> {
|
||||||
|
|
||||||
if low_index_mults || missing_pos {
|
if low_index_mults || missing_pos {
|
||||||
if let Some(n) = remaining_args.get(0) {
|
if let Some(n) = remaining_args.get(0) {
|
||||||
needs_val_of = match needs_val_of {
|
needs_val_of = if let Some(p) = self
|
||||||
ParseResult::ValuesDone => ParseResult::ValuesDone,
|
.app
|
||||||
_ => {
|
.get_positionals()
|
||||||
if let Some(p) = self
|
.find(|p| p.index == Some(pos_counter as u64))
|
||||||
.app
|
{
|
||||||
.get_positionals()
|
ParseResult::Pos(p.id.clone())
|
||||||
.find(|p| p.index == Some(pos_counter as u64))
|
} else {
|
||||||
{
|
ParseResult::ValuesDone
|
||||||
ParseResult::Pos(p.id.clone())
|
|
||||||
} else {
|
|
||||||
ParseResult::ValuesDone
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If the arg doesn't looks like a new_arg and it's not a
|
||||||
|
// subcommand, don't bump the position counter.
|
||||||
let n = ArgStr::new(n);
|
let n = ArgStr::new(n);
|
||||||
let sc_match = { self.possible_subcommand(&n).is_some() };
|
if self.is_new_arg(&n, &needs_val_of) || self.possible_subcommand(&n).is_some()
|
||||||
|
|
||||||
if self.is_new_arg(&n, &needs_val_of)
|
|
||||||
|| sc_match
|
|
||||||
|| !suggestions::did_you_mean(
|
|
||||||
&n.to_string_lossy(),
|
|
||||||
self.app.all_subcommand_names(),
|
|
||||||
)
|
|
||||||
.is_empty()
|
|
||||||
{
|
{
|
||||||
debug!("Parser::get_matches_with: Bumping the positional counter...");
|
debug!("Parser::get_matches_with: Bumping the positional counter...");
|
||||||
pos_counter += 1;
|
pos_counter += 1;
|
||||||
|
@ -548,7 +537,6 @@ impl<'help, 'app> Parser<'help, 'app> {
|
||||||
matcher.inc_occurrence_of(&grp);
|
matcher.inc_occurrence_of(&grp);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.app.settings.set(AS::ValidArgFound);
|
|
||||||
// Only increment the positional counter if it doesn't allow multiples
|
// Only increment the positional counter if it doesn't allow multiples
|
||||||
if !p.settings.is_set(ArgSettings::MultipleValues) {
|
if !p.settings.is_set(ArgSettings::MultipleValues) {
|
||||||
pos_counter += 1;
|
pos_counter += 1;
|
||||||
|
|
Loading…
Reference in a new issue