mirror of
https://github.com/clap-rs/clap
synced 2025-01-21 00:53:52 +00:00
fix: fixes rebase errors
This commit is contained in:
parent
87c88d6054
commit
4ff03096fb
5 changed files with 27 additions and 144 deletions
|
@ -18,11 +18,11 @@ use yaml_rust::Yaml;
|
||||||
// Internal
|
// Internal
|
||||||
use build::{Arg, ArgGroup, ArgSettings};
|
use build::{Arg, ArgGroup, ArgSettings};
|
||||||
use completions::{ComplGen, Shell};
|
use completions::{ComplGen, Shell};
|
||||||
|
use mkeymap::{KeyType, MKeyMap};
|
||||||
use output::fmt::ColorWhen;
|
use output::fmt::ColorWhen;
|
||||||
use output::{Help, Usage};
|
use output::{Help, Usage};
|
||||||
use parse::errors::Result as ClapResult;
|
use parse::errors::Result as ClapResult;
|
||||||
use parse::{ArgMatcher, ArgMatches, Parser};
|
use parse::{ArgMatcher, ArgMatches, Parser};
|
||||||
use mkeymap::{MKeyMap, KeyType};
|
|
||||||
use INTERNAL_ERROR_MSG;
|
use INTERNAL_ERROR_MSG;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -1733,7 +1733,7 @@ impl<'a, 'b> App<'a, 'b> {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
impl<'a, 'b> App<'a, 'b> {
|
impl<'a, 'b> App<'a, 'b> {
|
||||||
pub(crate) fn find(&self, name: &str) -> Option<&Arg<'a, 'b>> {
|
pub(crate) fn find(&self, name: &str) -> Option<&Arg<'a, 'b>> {
|
||||||
self.args.iter().find(|a| a.name == name)
|
self.args.values().find(|a| a.name == name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should we color the output? None=determined by output location, true=yes, false=no
|
// Should we color the output? None=determined by output location, true=yes, false=no
|
||||||
|
@ -1780,13 +1780,9 @@ impl<'a, 'b> App<'a, 'b> {
|
||||||
|
|
||||||
pub fn has_positionals(&self) -> bool { positionals!(self).count() > 0 }
|
pub fn has_positionals(&self) -> bool { positionals!(self).count() > 0 }
|
||||||
|
|
||||||
pub fn has_visible_opts(&self) -> bool {
|
pub fn has_visible_opts(&self) -> bool { opts!(self).any(|o| !o.is_set(ArgSettings::Hidden)) }
|
||||||
opts!(self).any(|o| !o.is_set(ArgSettings::Hidden))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_visible_flags(&self) -> bool {
|
pub fn has_visible_flags(&self) -> bool { flags!(self).any(|o| !o.is_set(ArgSettings::Hidden)) }
|
||||||
flags!(self).any(|o| !o.is_set(ArgSettings::Hidden))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_visible_positionals(&self) -> bool {
|
pub fn has_visible_positionals(&self) -> bool {
|
||||||
positionals!(self).any(|o| !o.is_set(ArgSettings::Hidden))
|
positionals!(self).any(|o| !o.is_set(ArgSettings::Hidden))
|
||||||
|
|
|
@ -1008,26 +1008,6 @@ macro_rules! subcommands_mut {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! groups {
|
|
||||||
($app:expr, $how:ident) => {
|
|
||||||
$app.groups.$how()
|
|
||||||
};
|
|
||||||
($app:expr) => {
|
|
||||||
groups!($app, iter)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! groups_mut {
|
|
||||||
($app:expr) => {
|
|
||||||
groups!($app, iter_mut)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// macro_rules! groups_mut {
|
|
||||||
// ($app:expr) => {
|
|
||||||
// groups!($app, iter_mut)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
macro_rules! groups_for_arg {
|
macro_rules! groups_for_arg {
|
||||||
($app:expr, $grp:expr) => {{
|
($app:expr, $grp:expr) => {{
|
||||||
debugln!("Parser::groups_for_arg: name={}", $grp);
|
debugln!("Parser::groups_for_arg: name={}", $grp);
|
||||||
|
@ -1049,30 +1029,6 @@ macro_rules! find {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// macro_rules! find_by_long {
|
|
||||||
// ($app:expr, $long:expr, $what:ident) => {{
|
|
||||||
// $what!($app)
|
|
||||||
// .filter(|a| a.long.is_some())
|
|
||||||
// .find(|a| match_alias!(a, $long, a.long.unwrap()))
|
|
||||||
// }};
|
|
||||||
// ($app:expr, $long:expr) => {{
|
|
||||||
// $app.args.iter()
|
|
||||||
// .filter(|a| a.long.is_some())
|
|
||||||
// .find(|a| match_alias!(a, $long, a.long.unwrap()))
|
|
||||||
// }};
|
|
||||||
// }
|
|
||||||
|
|
||||||
// macro_rules! find_by_short {
|
|
||||||
// ($app:expr, $short:expr, $what:ident) => {{
|
|
||||||
// $what!($app)
|
|
||||||
// .find(|a| a.short == Some($short))
|
|
||||||
// }};
|
|
||||||
// ($app:expr, $short:expr) => {{
|
|
||||||
// $app.args.iter()
|
|
||||||
// .find(|a| a.short == Some($short))
|
|
||||||
// }}
|
|
||||||
// }
|
|
||||||
|
|
||||||
macro_rules! find_subcmd_cloned {
|
macro_rules! find_subcmd_cloned {
|
||||||
($_self:expr, $sc:expr) => {{
|
($_self:expr, $sc:expr) => {{
|
||||||
subcommands_cloned!($_self)
|
subcommands_cloned!($_self)
|
||||||
|
@ -1087,29 +1043,6 @@ macro_rules! find_subcmd {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
// macro_rules! shorts {
|
|
||||||
// ($app:expr) => {{
|
|
||||||
// _shorts_longs!($app, short)
|
|
||||||
// }};
|
|
||||||
// }
|
|
||||||
|
|
||||||
// macro_rules! longs {
|
|
||||||
// ($app:expr) => {{
|
|
||||||
// $app.args.iter()
|
|
||||||
// .filter(|a| a.long.is_some())
|
|
||||||
// .map(|a| a.long.unwrap())
|
|
||||||
// .chain($app.args.iter()
|
|
||||||
// .filter(|a| a.aliases.is_some())
|
|
||||||
// .flat_map(|a| a.aliases.as_ref().unwrap().iter().map(|als| als.0)))
|
|
||||||
// }};
|
|
||||||
// }
|
|
||||||
|
|
||||||
// macro_rules! _shorts_longs {
|
|
||||||
// ($app:expr, $what:ident) => {{
|
|
||||||
// $app.args.iter().filter_map(|a| a.$what)
|
|
||||||
// }};
|
|
||||||
// }
|
|
||||||
|
|
||||||
//TODO change into one macro (repeated structure) + Positionals
|
//TODO change into one macro (repeated structure) + Positionals
|
||||||
macro_rules! longs {
|
macro_rules! longs {
|
||||||
($app:expr) => {{
|
($app:expr) => {{
|
||||||
|
|
|
@ -327,49 +327,6 @@ impl<'a, 'b, 'c, 'z> Usage<'a, 'b, 'c, 'z> {
|
||||||
for aa in self.p.app.unroll_requirements_for_arg(a, m) {
|
for aa in self.p.app.unroll_requirements_for_arg(a, m) {
|
||||||
unrolled_reqs.push(aa);
|
unrolled_reqs.push(aa);
|
||||||
}
|
}
|
||||||
}};
|
|
||||||
($a:ident, $what:ident, $how:ident, $v:ident, $p:ident) => {{
|
|
||||||
if let Some(rl) = $what!(self.0.app)
|
|
||||||
.filter(|a| a.requires.is_some())
|
|
||||||
.find(|arg| &arg.name == $a)
|
|
||||||
.map(|a| a.requires.as_ref().unwrap())
|
|
||||||
{
|
|
||||||
for &(_, r) in rl.iter() {
|
|
||||||
if !$p.contains(&r) {
|
|
||||||
debugln!(
|
|
||||||
"usage::get_required_usage_from:iter:{}: adding arg req={:?}",
|
|
||||||
$a,
|
|
||||||
r
|
|
||||||
);
|
|
||||||
$v.push(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}};
|
|
||||||
}
|
|
||||||
// initialize new_reqs
|
|
||||||
for a in reqs {
|
|
||||||
get_requires!(a, flags, iter, new_reqs, reqs);
|
|
||||||
get_requires!(a, opts, iter, new_reqs, reqs);
|
|
||||||
get_requires!(a, positionals, values, new_reqs, reqs);
|
|
||||||
get_requires!(@group a, new_reqs, reqs);
|
|
||||||
}
|
|
||||||
desc_reqs.extend_from_slice(&*new_reqs);
|
|
||||||
debugln!(
|
|
||||||
"usage::get_required_usage_from: after init desc_reqs={:?}",
|
|
||||||
desc_reqs
|
|
||||||
);
|
|
||||||
loop {
|
|
||||||
let mut tmp = vec![];
|
|
||||||
for a in &new_reqs {
|
|
||||||
get_requires!(a, flags, iter, tmp, desc_reqs);
|
|
||||||
get_requires!(a, opts, iter, tmp, desc_reqs);
|
|
||||||
get_requires!(a, positionals, values, tmp, desc_reqs);
|
|
||||||
get_requires!(@group a, tmp, desc_reqs);
|
|
||||||
}
|
|
||||||
if tmp.is_empty() {
|
|
||||||
debugln!("usage::get_required_usage_from: no more children");
|
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
unrolled_reqs.push(a);
|
unrolled_reqs.push(a);
|
||||||
}
|
}
|
||||||
|
@ -388,7 +345,7 @@ impl<'a, 'b, 'c, 'z> Usage<'a, 'b, 'c, 'z> {
|
||||||
unrolled_reqs
|
unrolled_reqs
|
||||||
.iter()
|
.iter()
|
||||||
.chain(incls.iter())
|
.chain(incls.iter())
|
||||||
.filter(|a| self.p.positionals.values().any(|p| &p == a))
|
.filter(|a| positionals!(self.p.app).any(|p| &&p.name == a))
|
||||||
.filter(|&pos| !m.contains(pos))
|
.filter(|&pos| !m.contains(pos))
|
||||||
.filter_map(|pos| self.p.app.find(pos))
|
.filter_map(|pos| self.p.app.find(pos))
|
||||||
.filter(|&pos| incl_last || !pos.is_set(ArgSettings::Last))
|
.filter(|&pos| incl_last || !pos.is_set(ArgSettings::Last))
|
||||||
|
@ -399,7 +356,7 @@ impl<'a, 'b, 'c, 'z> Usage<'a, 'b, 'c, 'z> {
|
||||||
unrolled_reqs
|
unrolled_reqs
|
||||||
.iter()
|
.iter()
|
||||||
.chain(incls.iter())
|
.chain(incls.iter())
|
||||||
.filter(|a| self.p.positionals.values().any(|p| &p == a))
|
.filter(|a| positionals!(self.p.app).any(|p| &&p.name == a))
|
||||||
.filter_map(|pos| self.p.app.find(pos))
|
.filter_map(|pos| self.p.app.find(pos))
|
||||||
.filter(|&pos| incl_last || !pos.is_set(ArgSettings::Last))
|
.filter(|&pos| incl_last || !pos.is_set(ArgSettings::Last))
|
||||||
.filter(|pos| !args_in_groups.contains(&pos.name))
|
.filter(|pos| !args_in_groups.contains(&pos.name))
|
||||||
|
|
|
@ -315,12 +315,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add conditional requirements
|
|
||||||
if let Some(ref r_ifs) = a.r_ifs {
|
|
||||||
for &(arg, val) in r_ifs {
|
|
||||||
self.r_ifs.push((arg, val, a.name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add args with default requirements
|
// Add args with default requirements
|
||||||
if a.is_set(ArgSettings::Required) {
|
if a.is_set(ArgSettings::Required) {
|
||||||
|
@ -359,10 +353,10 @@ where
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.count())
|
.count())
|
||||||
}) && self.positionals.values().last().map_or(false, |p_name| {
|
}) && positionals!(self.app).last().map_or(false, |p_name| {
|
||||||
!self
|
!self
|
||||||
.app
|
.app
|
||||||
.find(p_name)
|
.find(p_name.name)
|
||||||
.expect(INTERNAL_ERROR_MSG)
|
.expect(INTERNAL_ERROR_MSG)
|
||||||
.is_set(ArgSettings::Last)
|
.is_set(ArgSettings::Last)
|
||||||
}) {
|
}) {
|
||||||
|
@ -541,7 +535,8 @@ where
|
||||||
.filter(|x| if let KeyType::Position(_) = x { true } else { false })
|
.filter(|x| if let KeyType::Position(_) = x { true } else { false })
|
||||||
.count() - 1);
|
.count() - 1);
|
||||||
let missing_pos = self.is_set(AS::AllowMissingPositional)
|
let missing_pos = self.is_set(AS::AllowMissingPositional)
|
||||||
&& (pos_counter == (self
|
&& (pos_counter
|
||||||
|
== (self
|
||||||
.app
|
.app
|
||||||
.args
|
.args
|
||||||
.keys()
|
.keys()
|
||||||
|
@ -1053,9 +1048,9 @@ where
|
||||||
|
|
||||||
if opt.is_set(ArgSettings::TakesValue) {
|
if opt.is_set(ArgSettings::TakesValue) {
|
||||||
return Ok(self.parse_opt(val, opt, val.is_some(), matcher)?);
|
return Ok(self.parse_opt(val, opt, val.is_some(), matcher)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.parse_flag(flag, matcher)?;
|
self.parse_flag(opt, matcher)?;
|
||||||
|
|
||||||
return Ok(ParseResult::Flag);
|
return Ok(ParseResult::Flag);
|
||||||
} else if self.is_set(AS::AllowLeadingHyphen) {
|
} else if self.is_set(AS::AllowLeadingHyphen) {
|
||||||
|
@ -1491,21 +1486,23 @@ where
|
||||||
{
|
{
|
||||||
fn did_you_mean_error(&self, arg: &str, matcher: &mut ArgMatcher<'a>) -> ClapResult<()> {
|
fn did_you_mean_error(&self, arg: &str, matcher: &mut ArgMatcher<'a>) -> ClapResult<()> {
|
||||||
// Didn't match a flag or option
|
// Didn't match a flag or option
|
||||||
let longs = longs!(self.app).map(|x| x.to_string_lossy().into_owned()).collect::<Vec<_>>();
|
let longs = longs!(self.app)
|
||||||
|
.map(|x| x.to_string_lossy().into_owned())
|
||||||
let suffix =
|
.collect::<Vec<_>>();
|
||||||
suggestions::did_you_mean_flag_suffix(arg, longs.iter().map(|ref x| &x[..] ), &*self.app.subcommands);
|
|
||||||
|
let suffix = suggestions::did_you_mean_flag_suffix(
|
||||||
|
arg,
|
||||||
|
longs.iter().map(|ref x| &x[..]),
|
||||||
|
&*self.app.subcommands,
|
||||||
|
);
|
||||||
|
|
||||||
// Add the arg to the matches to build a proper usage string
|
// Add the arg to the matches to build a proper usage string
|
||||||
if let Some(ref name) = suffix.1 {
|
if let Some(ref name) = suffix.1 {
|
||||||
if let Some(opt) = self.app.args.get(KeyType::Long(OsString::from(name))) {
|
if let Some(opt) = self.app.args.get(KeyType::Long(OsString::from(name))) {
|
||||||
self.groups_for_arg(&*opt.name)
|
for g in groups_for_arg!(self.app, &opt.name) {
|
||||||
.and_then(|grps| Some(matcher.inc_occurrences_of(&*grps)));
|
matcher.inc_occurrence_of(g);
|
||||||
|
}
|
||||||
matcher.insert(&*opt.name);
|
matcher.insert(&*opt.name);
|
||||||
} else if let Some(flg) = self.app.args.get(KeyType::Long(&OsStr::new(name))) {
|
|
||||||
self.groups_for_arg(&*flg.name)
|
|
||||||
.and_then(|grps| Some(matcher.inc_occurrences_of(&*grps)));
|
|
||||||
matcher.insert(&*flg.name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1522,7 +1519,7 @@ where
|
||||||
.map(|&n| n)
|
.map(|&n| n)
|
||||||
.collect();
|
.collect();
|
||||||
Err(ClapError::unknown_argument(
|
Err(ClapError::unknown_argument(
|
||||||
&*used_arg,
|
&*format!("--{}", arg),
|
||||||
&*suffix.0,
|
&*suffix.0,
|
||||||
&*Usage::new(self).create_usage_with_title(&*used),
|
&*Usage::new(self).create_usage_with_title(&*used),
|
||||||
self.app.color(),
|
self.app.color(),
|
||||||
|
|
|
@ -517,7 +517,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
||||||
.p
|
.p
|
||||||
.app
|
.app
|
||||||
.args
|
.args
|
||||||
.iter()
|
.values()
|
||||||
.filter(|a| a.r_ifs.is_some())
|
.filter(|a| a.r_ifs.is_some())
|
||||||
.map(|a| (a, a.r_ifs.as_ref().unwrap()))
|
.map(|a| (a, a.r_ifs.as_ref().unwrap()))
|
||||||
{
|
{
|
||||||
|
@ -562,7 +562,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
||||||
.p
|
.p
|
||||||
.app
|
.app
|
||||||
.args
|
.args
|
||||||
.iter()
|
.values()
|
||||||
.filter(|a| a.r_unless.is_some())
|
.filter(|a| a.r_unless.is_some())
|
||||||
.filter(|a| !matcher.contains(a.name))
|
.filter(|a| !matcher.contains(a.name))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue