mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
depr(Arg.rs): adds deprecations in prep for v3
A full list of deprecations is: * Arg::last -> ArgSettings::Last * Arg::required -> ArgSettings::Required * Arg::require_equals -> ArgSettings::RequireEquals * Arg::allow_hyphen_values -> ArgSettings::AllowHyphenValues * Arg::takes_value -> ArgSettings::TakesValue * Arg::hide_possible_values -> ArgSettings::HidePossibleValues * Arg::hide_default_value -> ArgSettings::HideDefaultValue * Arg::multiple -> ArgSettings::Multiple (see Arg::multiple split) * Arg::multiple -> ArgSettings::MultipleValues (see Arg::multiple split) * Arg::multiple -> ArgSettings::MultipleOccurrences (see Arg::multiple split) * Arg::global -> ArgSettings::Global * Arg::empty_values -> ArgSettings::AllowEmptyValues * Arg::hidden -> ArgSettings::Hidden * Arg::case_insensitive -> ArgSettings::IgnoreCase * Arg::use_delimiter -> ArgSettings::UseDelimiter * Arg::require_delimiter -> ArgSettings::RequireDelimiter * Arg::hide_env_values -> ArgSettings::HideEnvValues * Arg::next_line_help -> ArgSettings::NextLineHelp * Arg::set -> Arg::unset_setting (consistent naming with App) * Arg::unset -> Arg::setting (consistent naming with App) Relates to #1037
This commit is contained in:
parent
e1f1b474a3
commit
6fc70d825c
14 changed files with 1887 additions and 1580 deletions
|
@ -296,6 +296,8 @@ impl<'w> Help<'w> {
|
||||||
/// Writes argument's possible values to the wrapped stream.
|
/// Writes argument's possible values to the wrapped stream.
|
||||||
fn val<'b, 'c>(&mut self, arg: &Arg<'b, 'c>) -> Result<String, io::Error> {
|
fn val<'b, 'c>(&mut self, arg: &Arg<'b, 'c>) -> Result<String, io::Error> {
|
||||||
debugln!("Help::val: arg={}", arg.name);
|
debugln!("Help::val: arg={}", arg.name);
|
||||||
|
let mult =
|
||||||
|
arg.is_set(ArgSettings::MultipleValues) || arg.is_set(ArgSettings::MultipleOccurrences);
|
||||||
if arg.is_set(ArgSettings::TakesValue) {
|
if arg.is_set(ArgSettings::TakesValue) {
|
||||||
let delim = if arg.is_set(ArgSettings::RequireDelimiter) {
|
let delim = if arg.is_set(ArgSettings::RequireDelimiter) {
|
||||||
arg.val_delim.expect(INTERNAL_ERROR_MSG)
|
arg.val_delim.expect(INTERNAL_ERROR_MSG)
|
||||||
|
@ -311,7 +313,7 @@ impl<'w> Help<'w> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let num = vec.len();
|
let num = vec.len();
|
||||||
if arg.is_set(ArgSettings::Multiple) && num == 1 {
|
if mult && num == 1 {
|
||||||
color!(self, "...", good)?;
|
color!(self, "...", good)?;
|
||||||
}
|
}
|
||||||
} else if let Some(num) = arg.num_vals {
|
} else if let Some(num) = arg.num_vals {
|
||||||
|
@ -322,12 +324,12 @@ impl<'w> Help<'w> {
|
||||||
write!(self.writer, "{}", delim)?;
|
write!(self.writer, "{}", delim)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if arg.is_set(ArgSettings::Multiple) && num == 1 {
|
if mult && num == 1 {
|
||||||
color!(self, "...", good)?;
|
color!(self, "...", good)?;
|
||||||
}
|
}
|
||||||
} else if arg.has_switch() {
|
} else if arg.has_switch() {
|
||||||
color!(self, "<{}>", arg.name, good)?;
|
color!(self, "<{}>", arg.name, good)?;
|
||||||
if arg.is_set(ArgSettings::Multiple) {
|
if mult {
|
||||||
color!(self, "...", good)?;
|
color!(self, "...", good)?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1564,8 +1564,8 @@ impl<'a, 'b> App<'a, 'b> {
|
||||||
assert!(
|
assert!(
|
||||||
positionals!(self).fold(0, |acc, p| if p.index == Some(idx as u64){acc+1}else{acc}) < 2,
|
positionals!(self).fold(0, |acc, p| if p.index == Some(idx as u64){acc+1}else{acc}) < 2,
|
||||||
"Argument '{}' has the same index as another positional \
|
"Argument '{}' has the same index as another positional \
|
||||||
argument\n\n\tUse Arg::multiple(true) to allow one positional argument \
|
argument\n\n\tUse Arg::setting(ArgSettings::MultipleValues) to allow one \
|
||||||
to take multiple values",
|
positional argument to take multiple values",
|
||||||
a.name
|
a.name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ where
|
||||||
|
|
||||||
// Next we verify that only the highest index has a .multiple(true) (if any)
|
// Next we verify that only the highest index has a .multiple(true) (if any)
|
||||||
if positionals!(self.app).any(|a| {
|
if positionals!(self.app).any(|a| {
|
||||||
a.is_set(ArgSettings::Multiple) && (a.index.unwrap_or(0) != highest_idx as u64)
|
a.is_set(ArgSettings::MultipleValues) && (a.index.unwrap_or(0) != highest_idx as u64)
|
||||||
}) {
|
}) {
|
||||||
// First we make sure if there is a positional that allows multiple values
|
// First we make sure if there is a positional that allows multiple values
|
||||||
// the one before it (second to last) has one of these:
|
// the one before it (second to last) has one of these:
|
||||||
|
@ -157,7 +157,8 @@ where
|
||||||
);
|
);
|
||||||
|
|
||||||
// We make sure if the second to last is Multiple the last is ArgSettings::Last
|
// We make sure if the second to last is Multiple the last is ArgSettings::Last
|
||||||
let ok = second_to_last.is_set(ArgSettings::Multiple) || last.is_set(ArgSettings::Last);
|
let ok = second_to_last.is_set(ArgSettings::MultipleValues)
|
||||||
|
|| last.is_set(ArgSettings::Last);
|
||||||
assert!(
|
assert!(
|
||||||
ok,
|
ok,
|
||||||
"Only the last positional argument, or second to last positional \
|
"Only the last positional argument, or second to last positional \
|
||||||
|
@ -166,15 +167,15 @@ where
|
||||||
|
|
||||||
// Next we check how many have both Multiple and not a specific number of values set
|
// Next we check how many have both Multiple and not a specific number of values set
|
||||||
let count = positionals!(self.app).fold(0, |acc, p| {
|
let count = positionals!(self.app).fold(0, |acc, p| {
|
||||||
if p.settings.is_set(ArgSettings::Multiple) && p.num_vals.is_none() {
|
if p.settings.is_set(ArgSettings::MultipleValues) && p.num_vals.is_none() {
|
||||||
acc + 1
|
acc + 1
|
||||||
} else {
|
} else {
|
||||||
acc
|
acc
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let ok = count <= 1
|
let ok = count <= 1
|
||||||
|| (last.is_set(ArgSettings::Last) && last.is_set(ArgSettings::Multiple)
|
|| (last.is_set(ArgSettings::Last) && last.is_set(ArgSettings::MultipleValues)
|
||||||
&& second_to_last.is_set(ArgSettings::Multiple)
|
&& second_to_last.is_set(ArgSettings::MultipleValues)
|
||||||
&& count == 2);
|
&& count == 2);
|
||||||
assert!(
|
assert!(
|
||||||
ok,
|
ok,
|
||||||
|
@ -307,7 +308,7 @@ where
|
||||||
debug_assert!(self._verify_positionals());
|
debug_assert!(self._verify_positionals());
|
||||||
// Set the LowIndexMultiple flag if required
|
// Set the LowIndexMultiple flag if required
|
||||||
if positionals!(self.app).any(|a| {
|
if positionals!(self.app).any(|a| {
|
||||||
a.is_set(ArgSettings::Multiple)
|
a.is_set(ArgSettings::MultipleValues)
|
||||||
&& (a.index.unwrap_or(0) as usize != self.positionals.len())
|
&& (a.index.unwrap_or(0) as usize != self.positionals.len())
|
||||||
}) && self.positionals.values().last().map_or(false, |p_name| {
|
}) && self.positionals.values().last().map_or(false, |p_name| {
|
||||||
!find!(self.app, p_name)
|
!find!(self.app, p_name)
|
||||||
|
@ -535,7 +536,7 @@ where
|
||||||
|
|
||||||
self.app.settings.set(AS::ValidArgFound);
|
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::Multiple) {
|
if !p.settings.is_set(ArgSettings::MultipleValues) {
|
||||||
pos_counter += 1;
|
pos_counter += 1;
|
||||||
}
|
}
|
||||||
self.app.settings.set(AS::ValidArgFound);
|
self.app.settings.set(AS::ValidArgFound);
|
||||||
|
@ -721,7 +722,7 @@ where
|
||||||
if help_help {
|
if help_help {
|
||||||
let mut pb = Arg::with_name("subcommand")
|
let mut pb = Arg::with_name("subcommand")
|
||||||
.index(1)
|
.index(1)
|
||||||
.set(ArgSettings::Multiple)
|
.setting(ArgSettings::MultipleValues)
|
||||||
.help("The subcommand whose help message to display");
|
.help("The subcommand whose help message to display");
|
||||||
pb._build();
|
pb._build();
|
||||||
parser.positionals.insert(1, pb.name);
|
parser.positionals.insert(1, pb.name);
|
||||||
|
@ -754,11 +755,11 @@ where
|
||||||
let arg_allows_tac = match needs_val_of {
|
let arg_allows_tac = match needs_val_of {
|
||||||
ParseResult::Opt(name) => {
|
ParseResult::Opt(name) => {
|
||||||
let o = find!(self.app, &name).expect(INTERNAL_ERROR_MSG);
|
let o = find!(self.app, &name).expect(INTERNAL_ERROR_MSG);
|
||||||
(o.is_set(ArgSettings::AllowLeadingHyphen) || app_wide_settings)
|
(o.is_set(ArgSettings::AllowHyphenValues) || app_wide_settings)
|
||||||
}
|
}
|
||||||
ParseResult::Pos(name) => {
|
ParseResult::Pos(name) => {
|
||||||
let p = find!(self.app, &name).expect(INTERNAL_ERROR_MSG);
|
let p = find!(self.app, &name).expect(INTERNAL_ERROR_MSG);
|
||||||
(p.is_set(ArgSettings::AllowLeadingHyphen) || app_wide_settings)
|
(p.is_set(ArgSettings::AllowHyphenValues) || app_wide_settings)
|
||||||
}
|
}
|
||||||
ParseResult::ValuesDone => return true,
|
ParseResult::ValuesDone => return true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
@ -1061,7 +1062,7 @@ where
|
||||||
debugln!("Parser::parse_opt; opt.settings={:?}", opt.settings);
|
debugln!("Parser::parse_opt; opt.settings={:?}", opt.settings);
|
||||||
let mut has_eq = false;
|
let mut has_eq = false;
|
||||||
let no_val = val.is_none();
|
let no_val = val.is_none();
|
||||||
let empty_vals = opt.is_set(ArgSettings::EmptyValues);
|
let empty_vals = opt.is_set(ArgSettings::AllowEmptyValues);
|
||||||
let min_vals_zero = opt.min_vals.unwrap_or(1) == 0;
|
let min_vals_zero = opt.min_vals.unwrap_or(1) == 0;
|
||||||
let needs_eq = opt.is_set(ArgSettings::RequireEquals);
|
let needs_eq = opt.is_set(ArgSettings::RequireEquals);
|
||||||
|
|
||||||
|
@ -1101,7 +1102,8 @@ where
|
||||||
.and_then(|vec| Some(matcher.inc_occurrences_of(&*vec)));
|
.and_then(|vec| Some(matcher.inc_occurrences_of(&*vec)));
|
||||||
|
|
||||||
let needs_delim = opt.is_set(ArgSettings::RequireDelimiter);
|
let needs_delim = opt.is_set(ArgSettings::RequireDelimiter);
|
||||||
let mult = opt.is_set(ArgSettings::Multiple);
|
let mult = opt.is_set(ArgSettings::MultipleValues);
|
||||||
|
// @TODO @soundness: if doesn't have an equal, but requires equal is ValuesDone?!
|
||||||
if no_val && min_vals_zero && !has_eq && needs_eq {
|
if no_val && min_vals_zero && !has_eq && needs_eq {
|
||||||
debugln!("Parser::parse_opt: More arg vals not required...");
|
debugln!("Parser::parse_opt: More arg vals not required...");
|
||||||
return Ok(ParseResult::ValuesDone);
|
return Ok(ParseResult::ValuesDone);
|
||||||
|
|
|
@ -96,7 +96,7 @@ impl<'a, 'b, 'c, 'z> Usage<'a, 'b, 'c, 'z> {
|
||||||
let has_last = positionals!(self.0.app).any(|p| p.is_set(ArgSettings::Last));
|
let has_last = positionals!(self.0.app).any(|p| p.is_set(ArgSettings::Last));
|
||||||
// places a '--' in the usage string if there are args and options
|
// places a '--' in the usage string if there are args and options
|
||||||
// supporting multiple values
|
// supporting multiple values
|
||||||
if opts!(self.0.app).any(|o| o.is_set(ArgSettings::Multiple))
|
if opts!(self.0.app).any(|o| o.is_set(ArgSettings::MultipleValues))
|
||||||
&& positionals!(self.0.app).any(|p| !p.is_set(ArgSettings::Required))
|
&& positionals!(self.0.app).any(|p| !p.is_set(ArgSettings::Required))
|
||||||
&& !(self.0.app.has_visible_subcommands()
|
&& !(self.0.app.has_visible_subcommands()
|
||||||
|| self.0.is_set(AS::AllowExternalSubcommands)) && !has_last
|
|| self.0.is_set(AS::AllowExternalSubcommands)) && !has_last
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
||||||
if let Some(ref p_vals) = arg.possible_vals {
|
if let Some(ref p_vals) = arg.possible_vals {
|
||||||
debugln!("Validator::validate_arg_values: possible_vals={:?}", p_vals);
|
debugln!("Validator::validate_arg_values: possible_vals={:?}", p_vals);
|
||||||
let val_str = val.to_string_lossy();
|
let val_str = val.to_string_lossy();
|
||||||
let ok = if arg.is_set(ArgSettings::CaseInsensitive) {
|
let ok = if arg.is_set(ArgSettings::IgnoreCase) {
|
||||||
p_vals.iter().any(|pv| pv.eq_ignore_ascii_case(&*val_str))
|
p_vals.iter().any(|pv| pv.eq_ignore_ascii_case(&*val_str))
|
||||||
} else {
|
} else {
|
||||||
p_vals.contains(&&*val_str)
|
p_vals.contains(&&*val_str)
|
||||||
|
@ -110,7 +110,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !arg.is_set(ArgSettings::EmptyValues) && val.is_empty_()
|
if !arg.is_set(ArgSettings::AllowEmptyValues) && val.is_empty_()
|
||||||
&& matcher.contains(&*arg.name)
|
&& matcher.contains(&*arg.name)
|
||||||
{
|
{
|
||||||
debugln!("Validator::validate_arg_values: illegal empty val found");
|
debugln!("Validator::validate_arg_values: illegal empty val found");
|
||||||
|
@ -292,7 +292,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
||||||
matcher: &ArgMatcher<'a>,
|
matcher: &ArgMatcher<'a>,
|
||||||
) -> ClapResult<()> {
|
) -> ClapResult<()> {
|
||||||
debugln!("Validator::validate_arg_num_occurs: a={};", a.name);
|
debugln!("Validator::validate_arg_num_occurs: a={};", a.name);
|
||||||
if ma.occurs > 1 && !a.is_set(ArgSettings::Multiple) {
|
if ma.occurs > 1 && !a.is_set(ArgSettings::MultipleOccurrences) {
|
||||||
// Not the first time, and we don't allow multiples
|
// Not the first time, and we don't allow multiples
|
||||||
return Err(Error::unexpected_multiple_usage(
|
return Err(Error::unexpected_multiple_usage(
|
||||||
a,
|
a,
|
||||||
|
@ -312,7 +312,7 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
||||||
debugln!("Validator::validate_arg_num_vals;");
|
debugln!("Validator::validate_arg_num_vals;");
|
||||||
if let Some(num) = a.num_vals {
|
if let Some(num) = a.num_vals {
|
||||||
debugln!("Validator::validate_arg_num_vals: num_vals set...{}", num);
|
debugln!("Validator::validate_arg_num_vals: num_vals set...{}", num);
|
||||||
let should_err = if a.is_set(ArgSettings::Multiple) {
|
let should_err = if a.is_set(ArgSettings::MultipleValues) {
|
||||||
((ma.vals.len() as u64) % num) != 0
|
((ma.vals.len() as u64) % num) != 0
|
||||||
} else {
|
} else {
|
||||||
num != (ma.vals.len() as u64)
|
num != (ma.vals.len() as u64)
|
||||||
|
@ -322,13 +322,14 @@ impl<'a, 'b, 'c, 'z> Validator<'a, 'b, 'c, 'z> {
|
||||||
return Err(Error::wrong_number_of_values(
|
return Err(Error::wrong_number_of_values(
|
||||||
a,
|
a,
|
||||||
num,
|
num,
|
||||||
if a.is_set(ArgSettings::Multiple) {
|
if a.is_set(ArgSettings::MultipleValues) {
|
||||||
(ma.vals.len() % num as usize)
|
(ma.vals.len() % num as usize)
|
||||||
} else {
|
} else {
|
||||||
ma.vals.len()
|
ma.vals.len()
|
||||||
},
|
},
|
||||||
if ma.vals.len() == 1
|
if ma.vals.len() == 1
|
||||||
|| (a.is_set(ArgSettings::Multiple) && (ma.vals.len() % num as usize) == 1)
|
|| (a.is_set(ArgSettings::MultipleValues)
|
||||||
|
&& (ma.vals.len() % num as usize) == 1)
|
||||||
{
|
{
|
||||||
"as"
|
"as"
|
||||||
} else {
|
} else {
|
||||||
|
|
1180
src/args/arg.rs
1180
src/args/arg.rs
File diff suppressed because it is too large
Load diff
|
@ -132,7 +132,7 @@ impl<'a> ArgMatcher<'a> {
|
||||||
if let Some(ma) = self.get(o.name) {
|
if let Some(ma) = self.get(o.name) {
|
||||||
if let Some(num) = o.num_vals {
|
if let Some(num) = o.num_vals {
|
||||||
debugln!("ArgMatcher::needs_more_vals: num_vals...{}", num);
|
debugln!("ArgMatcher::needs_more_vals: num_vals...{}", num);
|
||||||
return if o.is_set(ArgSettings::Multiple) {
|
return if o.is_set(ArgSettings::MultipleValues) {
|
||||||
((ma.vals.len() as u64) % num) != 0
|
((ma.vals.len() as u64) % num) != 0
|
||||||
} else {
|
} else {
|
||||||
num != (ma.vals.len() as u64)
|
num != (ma.vals.len() as u64)
|
||||||
|
@ -144,7 +144,7 @@ impl<'a> ArgMatcher<'a> {
|
||||||
debugln!("ArgMatcher::needs_more_vals: min_vals...true");
|
debugln!("ArgMatcher::needs_more_vals: min_vals...true");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return o.is_set(ArgSettings::Multiple);
|
return o.is_set(ArgSettings::MultipleValues);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,11 +336,11 @@ impl<'a> ArgMatches<'a> {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use clap::{App, Arg};
|
/// # use clap::{App, Arg, ArgSettings};
|
||||||
/// let m = App::new("myprog")
|
/// let m = App::new("myprog")
|
||||||
/// .arg(Arg::with_name("debug")
|
/// .arg(Arg::with_name("debug")
|
||||||
/// .short("d")
|
/// .short("d")
|
||||||
/// .multiple(true))
|
/// .setting(ArgSettings::MultipleOccurrences))
|
||||||
/// .get_matches_from(vec![
|
/// .get_matches_from(vec![
|
||||||
/// "myprog", "-d", "-d", "-d"
|
/// "myprog", "-d", "-d", "-d"
|
||||||
/// ]);
|
/// ]);
|
||||||
|
@ -351,11 +351,11 @@ impl<'a> ArgMatches<'a> {
|
||||||
/// This next example shows that counts actual uses of the argument, not just `-`'s
|
/// This next example shows that counts actual uses of the argument, not just `-`'s
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use clap::{App, Arg};
|
/// # use clap::{App, Arg, ArgSettings};
|
||||||
/// let m = App::new("myprog")
|
/// let m = App::new("myprog")
|
||||||
/// .arg(Arg::with_name("debug")
|
/// .arg(Arg::with_name("debug")
|
||||||
/// .short("d")
|
/// .short("d")
|
||||||
/// .multiple(true))
|
/// .setting(ArgSettings::MultipleOccurrences))
|
||||||
/// .arg(Arg::with_name("flag")
|
/// .arg(Arg::with_name("flag")
|
||||||
/// .short("f"))
|
/// .short("f"))
|
||||||
/// .get_matches_from(vec![
|
/// .get_matches_from(vec![
|
||||||
|
|
1008
src/args/settings.rs
1008
src/args/settings.rs
File diff suppressed because it is too large
Load diff
|
@ -179,7 +179,9 @@ complete -F _{name} -o bashdefault -o default {name}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
let num = vec.len();
|
let num = vec.len();
|
||||||
if o.is_set(ArgSettings::Multiple) && num == 1 {
|
if (o.is_set(ArgSettings::MultipleValues) || o.is_set(ArgSettings::MultipleOccurrences))
|
||||||
|
&& num == 1
|
||||||
|
{
|
||||||
ret = format!("{}...", ret);
|
ret = format!("{}...", ret);
|
||||||
}
|
}
|
||||||
} else if let Some(num) = o.num_vals {
|
} else if let Some(num) = o.num_vals {
|
||||||
|
@ -192,12 +194,14 @@ complete -F _{name} -o bashdefault -o default {name}
|
||||||
if it.peek().is_some() { " " } else { "" }
|
if it.peek().is_some() { " " } else { "" }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if o.is_set(ArgSettings::Multiple) && num == 1 {
|
if (o.is_set(ArgSettings::MultipleValues) || o.is_set(ArgSettings::MultipleOccurrences))
|
||||||
|
&& num == 1
|
||||||
|
{
|
||||||
ret = format!("{}...", ret);
|
ret = format!("{}...", ret);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = format!("<{}>", o.name);
|
ret = format!("<{}>", o.name);
|
||||||
if o.is_set(ArgSettings::Multiple) {
|
if o.is_set(ArgSettings::MultipleValues) || o.is_set(ArgSettings::MultipleOccurrences) {
|
||||||
ret = format!("{}...", ret);
|
ret = format!("{}...", ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -346,7 +346,11 @@ fn write_opts_of(p: &App) -> String {
|
||||||
format!("({})", conflicts)
|
format!("({})", conflicts)
|
||||||
};
|
};
|
||||||
|
|
||||||
let multiple = if o.is_set(ArgSettings::Multiple) {
|
// @TODO @soundness should probably be either multiple occurrences or multiple values and
|
||||||
|
// not both
|
||||||
|
let multiple = if o.is_set(ArgSettings::MultipleOccurrences)
|
||||||
|
|| o.is_set(ArgSettings::MultipleValues)
|
||||||
|
{
|
||||||
"*"
|
"*"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
|
@ -407,7 +411,7 @@ fn write_flags_of(p: &App) -> String {
|
||||||
format!("({})", conflicts)
|
format!("({})", conflicts)
|
||||||
};
|
};
|
||||||
|
|
||||||
let multiple = if f.is_set(ArgSettings::Multiple) {
|
let multiple = if f.is_set(ArgSettings::MultipleOccurrences) {
|
||||||
"*"
|
"*"
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
|
|
|
@ -108,12 +108,12 @@ pub enum ErrorKind {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// # use clap::{App, Arg, ErrorKind};
|
/// # use clap::{App, Arg, ErrorKind, ArgSettings};
|
||||||
/// let res = App::new("prog")
|
/// let res = App::new("prog")
|
||||||
/// .arg(Arg::with_name("color")
|
/// .arg(Arg::with_name("color")
|
||||||
/// .long("color")
|
/// .setting(ArgSettings::TakesValue)
|
||||||
/// .empty_values(false))
|
/// .long("color"))
|
||||||
/// .get_matches_from_safe(vec!["prog", "--color="]);
|
/// .try_get_matches_from(vec!["prog", "--color="]);
|
||||||
/// assert!(res.is_err());
|
/// assert!(res.is_err());
|
||||||
/// assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
|
/// assert_eq!(res.unwrap_err().kind, ErrorKind::EmptyValue);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -136,7 +136,7 @@ pub enum ErrorKind {
|
||||||
/// let result = App::new("prog")
|
/// let result = App::new("prog")
|
||||||
/// .arg(Arg::with_name("num")
|
/// .arg(Arg::with_name("num")
|
||||||
/// .validator(is_numeric))
|
/// .validator(is_numeric))
|
||||||
/// .get_matches_from_safe(vec!["prog", "NotANumber"]);
|
/// .try_get_matches_from(vec!["prog", "NotANumber"]);
|
||||||
/// assert!(result.is_err());
|
/// assert!(result.is_err());
|
||||||
/// assert_eq!(result.unwrap_err().kind, ErrorKind::ValueValidation);
|
/// assert_eq!(result.unwrap_err().kind, ErrorKind::ValueValidation);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -153,7 +153,7 @@ pub enum ErrorKind {
|
||||||
/// .arg(Arg::with_name("arg")
|
/// .arg(Arg::with_name("arg")
|
||||||
/// .multiple(true)
|
/// .multiple(true)
|
||||||
/// .max_values(2))
|
/// .max_values(2))
|
||||||
/// .get_matches_from_safe(vec!["prog", "too", "many", "values"]);
|
/// .try_get_matches_from(vec!["prog", "too", "many", "values"]);
|
||||||
/// assert!(result.is_err());
|
/// assert!(result.is_err());
|
||||||
/// assert_eq!(result.unwrap_err().kind, ErrorKind::TooManyValues);
|
/// assert_eq!(result.unwrap_err().kind, ErrorKind::TooManyValues);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -171,7 +171,7 @@ pub enum ErrorKind {
|
||||||
/// .arg(Arg::with_name("some_opt")
|
/// .arg(Arg::with_name("some_opt")
|
||||||
/// .long("opt")
|
/// .long("opt")
|
||||||
/// .min_values(3))
|
/// .min_values(3))
|
||||||
/// .get_matches_from_safe(vec!["prog", "--opt", "too", "few"]);
|
/// .try_get_matches_from(vec!["prog", "--opt", "too", "few"]);
|
||||||
/// assert!(result.is_err());
|
/// assert!(result.is_err());
|
||||||
/// assert_eq!(result.unwrap_err().kind, ErrorKind::TooFewValues);
|
/// assert_eq!(result.unwrap_err().kind, ErrorKind::TooFewValues);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -191,7 +191,7 @@ pub enum ErrorKind {
|
||||||
/// .long("opt")
|
/// .long("opt")
|
||||||
/// .takes_value(true)
|
/// .takes_value(true)
|
||||||
/// .number_of_values(2))
|
/// .number_of_values(2))
|
||||||
/// .get_matches_from_safe(vec!["prog", "--opt", "wrong"]);
|
/// .try_get_matches_from(vec!["prog", "--opt", "wrong"]);
|
||||||
/// assert!(result.is_err());
|
/// assert!(result.is_err());
|
||||||
/// assert_eq!(result.unwrap_err().kind, ErrorKind::WrongNumberOfValues);
|
/// assert_eq!(result.unwrap_err().kind, ErrorKind::WrongNumberOfValues);
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -213,7 +213,7 @@ pub enum ErrorKind {
|
||||||
/// .conflicts_with("color"))
|
/// .conflicts_with("color"))
|
||||||
/// .arg(Arg::with_name("color")
|
/// .arg(Arg::with_name("color")
|
||||||
/// .long("color"))
|
/// .long("color"))
|
||||||
/// .get_matches_from_safe(vec!["prog", "--debug", "--color"]);
|
/// .try_get_matches_from(vec!["prog", "--debug", "--color"]);
|
||||||
/// assert!(result.is_err());
|
/// assert!(result.is_err());
|
||||||
/// assert_eq!(result.unwrap_err().kind, ErrorKind::ArgumentConflict);
|
/// assert_eq!(result.unwrap_err().kind, ErrorKind::ArgumentConflict);
|
||||||
/// ```
|
/// ```
|
||||||
|
|
|
@ -516,6 +516,8 @@
|
||||||
#![doc(html_root_url = "https://docs.rs/clap/2.29.2")]
|
#![doc(html_root_url = "https://docs.rs/clap/2.29.2")]
|
||||||
#![deny(missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts,
|
#![deny(missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts,
|
||||||
unused_import_braces, unused_allocation)]
|
unused_import_braces, unused_allocation)]
|
||||||
|
// @TODO @v3-beta: remove me!
|
||||||
|
#![allow(deprecated)]
|
||||||
// Lints we'd like to deny but are currently failing for upstream crates
|
// Lints we'd like to deny but are currently failing for upstream crates
|
||||||
// unused_qualifications (bitflags, clippy)
|
// unused_qualifications (bitflags, clippy)
|
||||||
// trivial_numeric_casts (bitflags)
|
// trivial_numeric_casts (bitflags)
|
||||||
|
|
1176
src/usage_parser.rs
1176
src/usage_parser.rs
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue