mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
Rename NoEmptyValues to ForbidEmptyValues
This commit is contained in:
parent
49954c28ad
commit
f029047c03
8 changed files with 21 additions and 19 deletions
|
@ -67,7 +67,7 @@ fn assert_app_flags(arg: &Arg) {
|
|||
}
|
||||
}
|
||||
|
||||
checker!(NoEmptyValues requires TakesValue);
|
||||
checker!(ForbidEmptyValues requires TakesValue);
|
||||
checker!(RequireDelimiter requires TakesValue | UseValueDelimiter);
|
||||
checker!(HidePossibleValues requires TakesValue);
|
||||
checker!(AllowHyphenValues requires TakesValue);
|
||||
|
|
|
@ -4217,9 +4217,9 @@ impl<'help> Arg<'help> {
|
|||
#[inline]
|
||||
pub fn forbid_empty_values(self, empty: bool) -> Self {
|
||||
if empty {
|
||||
self.setting(ArgSettings::NoEmptyValues)
|
||||
self.setting(ArgSettings::ForbidEmptyValues)
|
||||
} else {
|
||||
self.unset_setting(ArgSettings::NoEmptyValues)
|
||||
self.unset_setting(ArgSettings::ForbidEmptyValues)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ impl_settings! { ArgSettings, ArgFlags,
|
|||
Required("required") => Flags::REQUIRED,
|
||||
MultipleOccurrences("multipleoccurrences") => Flags::MULTIPLE_OCC,
|
||||
MultipleValues("multiplevalues") => Flags::MULTIPLE_VALS,
|
||||
NoEmptyValues("noemptyvalues") => Flags::NO_EMPTY_VALS,
|
||||
ForbidEmptyValues("forbidemptyvalues") => Flags::NO_EMPTY_VALS,
|
||||
Hidden("hidden") => Flags::HIDDEN,
|
||||
TakesValue("takesvalue") => Flags::TAKES_VAL,
|
||||
UseValueDelimiter("usevaluedelimiter") => Flags::USE_DELIM,
|
||||
|
@ -80,8 +80,8 @@ pub enum ArgSettings {
|
|||
MultipleValues,
|
||||
/// Allows an arg to appear multiple times
|
||||
MultipleOccurrences,
|
||||
/// Disallows an arg from accepting empty values such as `""`
|
||||
NoEmptyValues,
|
||||
/// Forbids an arg from accepting empty values such as `""`
|
||||
ForbidEmptyValues,
|
||||
/// Hides an arg from the help message
|
||||
Hidden,
|
||||
/// Allows an argument to take a value (such as `--option value`)
|
||||
|
@ -130,8 +130,8 @@ mod test {
|
|||
ArgSettings::AllowHyphenValues
|
||||
);
|
||||
assert_eq!(
|
||||
"noemptyvalues".parse::<ArgSettings>().unwrap(),
|
||||
ArgSettings::NoEmptyValues
|
||||
"forbidemptyvalues".parse::<ArgSettings>().unwrap(),
|
||||
ArgSettings::ForbidEmptyValues
|
||||
);
|
||||
assert_eq!(
|
||||
"hidepossiblevalues".parse::<ArgSettings>().unwrap(),
|
||||
|
|
|
@ -116,7 +116,7 @@ pub enum ErrorKind {
|
|||
/// let res = App::new("prog")
|
||||
/// .arg(Arg::new("color")
|
||||
/// .setting(ArgSettings::TakesValue)
|
||||
/// .setting(ArgSettings::NoEmptyValues)
|
||||
/// .setting(ArgSettings::ForbidEmptyValues)
|
||||
/// .long("color"))
|
||||
/// .try_get_matches_from(vec!["prog", "--color="]);
|
||||
/// assert!(res.is_err());
|
||||
|
|
|
@ -1153,7 +1153,7 @@ impl<'help, 'app> Parser<'help, 'app> {
|
|||
// has_eq: --flag=value
|
||||
let mut has_eq = false;
|
||||
let no_val = val.is_none();
|
||||
let no_empty_vals = opt.is_set(ArgSettings::NoEmptyValues);
|
||||
let no_empty_vals = opt.is_set(ArgSettings::ForbidEmptyValues);
|
||||
let min_vals_zero = opt.min_vals.unwrap_or(1) == 0;
|
||||
let require_equals = opt.is_set(ArgSettings::RequireEquals);
|
||||
|
||||
|
|
|
@ -125,7 +125,9 @@ impl<'help, 'app, 'parser> Validator<'help, 'app, 'parser> {
|
|||
));
|
||||
}
|
||||
}
|
||||
if arg.is_set(ArgSettings::NoEmptyValues) && val.is_empty() && matcher.contains(&arg.id)
|
||||
if arg.is_set(ArgSettings::ForbidEmptyValues)
|
||||
&& val.is_empty()
|
||||
&& matcher.contains(&arg.id)
|
||||
{
|
||||
debug!("Validator::validate_arg_values: illegal empty val found");
|
||||
return Err(Error::empty_value(
|
||||
|
|
|
@ -55,7 +55,7 @@ fn no_empty_values_with_equals() {
|
|||
Arg::new("config")
|
||||
.long("config")
|
||||
.takes_value(true)
|
||||
.setting(ArgSettings::NoEmptyValues),
|
||||
.setting(ArgSettings::ForbidEmptyValues),
|
||||
)
|
||||
.try_get_matches_from(&["config", "--config="]);
|
||||
assert!(m.is_err());
|
||||
|
@ -66,7 +66,7 @@ fn no_empty_values_with_equals() {
|
|||
Arg::new("config")
|
||||
.short('c')
|
||||
.takes_value(true)
|
||||
.setting(ArgSettings::NoEmptyValues),
|
||||
.setting(ArgSettings::ForbidEmptyValues),
|
||||
)
|
||||
.try_get_matches_from(&["config", "-c="]);
|
||||
assert!(m.is_err());
|
||||
|
@ -80,7 +80,7 @@ fn no_empty_values_without_equals() {
|
|||
Arg::new("config")
|
||||
.long("config")
|
||||
.takes_value(true)
|
||||
.setting(ArgSettings::NoEmptyValues),
|
||||
.setting(ArgSettings::ForbidEmptyValues),
|
||||
)
|
||||
.try_get_matches_from(&["config", "--config"]);
|
||||
assert!(m.is_err());
|
||||
|
@ -91,7 +91,7 @@ fn no_empty_values_without_equals() {
|
|||
Arg::new("config")
|
||||
.short('c')
|
||||
.takes_value(true)
|
||||
.setting(ArgSettings::NoEmptyValues),
|
||||
.setting(ArgSettings::ForbidEmptyValues),
|
||||
)
|
||||
.try_get_matches_from(&["config", "-c"]);
|
||||
assert!(m.is_err());
|
||||
|
@ -104,7 +104,7 @@ fn no_empty_values_without_equals_but_requires_equals() {
|
|||
Arg::new("config")
|
||||
.long("config")
|
||||
.takes_value(true)
|
||||
.setting(ArgSettings::NoEmptyValues)
|
||||
.setting(ArgSettings::ForbidEmptyValues)
|
||||
.setting(ArgSettings::RequireEquals),
|
||||
);
|
||||
let m = app.clone().try_get_matches_from(&["config", "--config"]);
|
||||
|
|
|
@ -34,7 +34,7 @@ fn require_equals_fail() {
|
|||
.arg(
|
||||
Arg::new("cfg")
|
||||
.setting(ArgSettings::RequireEquals)
|
||||
.setting(ArgSettings::NoEmptyValues)
|
||||
.setting(ArgSettings::ForbidEmptyValues)
|
||||
.setting(ArgSettings::TakesValue)
|
||||
.long("config"),
|
||||
)
|
||||
|
@ -105,7 +105,7 @@ fn require_equals_no_empty_values_fail() {
|
|||
Arg::new("cfg")
|
||||
.setting(ArgSettings::TakesValue)
|
||||
.setting(ArgSettings::RequireEquals)
|
||||
.setting(ArgSettings::NoEmptyValues)
|
||||
.setting(ArgSettings::ForbidEmptyValues)
|
||||
.long("config"),
|
||||
)
|
||||
.arg(Arg::new("some"))
|
||||
|
@ -425,7 +425,7 @@ fn issue_665() {
|
|||
.arg("-v, --reroll-count=[N] 'Mark the patch series as PATCH vN'")
|
||||
.arg(
|
||||
Arg::from("--subject-prefix [Subject-Prefix] 'Use [Subject-Prefix] instead of the standard [PATCH] prefix'")
|
||||
.setting(ArgSettings::NoEmptyValues)
|
||||
.setting(ArgSettings::ForbidEmptyValues)
|
||||
)
|
||||
.try_get_matches_from(vec!["test", "--subject-prefix", "-v", "2"]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue