Rename required_unless_eq_* to required_unless_present_*

This commit is contained in:
Pavan Kumar Sunkara 2020-08-29 11:48:35 +02:00
parent 769372f651
commit 9e381f92a9
6 changed files with 47 additions and 38 deletions

View file

@ -112,7 +112,8 @@ jobs:
- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.40.0
override: true
- name: Checkout
uses: actions/checkout@v2
- name: Ready cache

View file

@ -21,8 +21,8 @@ TODO: `cargo`, `std` features
* `Arg::required_if` => `Arg::required_if_eq`
* `Arg::required_ifs` => `Arg::required_if_eq_any`
* `Arg::required_unless` => `Arg::required_unless_present`
* `Arg::required_unless_one` => `Arg::required_unless_eq_any`
* `Arg::required_unless_all` => `Arg::required_unless_eq_all`
* `Arg::required_unless_one` => `Arg::required_unless_present_any`
* `Arg::required_unless_all` => `Arg::required_unless_present_all`
* **ArgGroup**
* `ArgGroup::from_yaml` => `ArgGroup::from`
* `ArgGroup::with_name` => `ArgGroup::new`

View file

@ -315,7 +315,7 @@ where
.arg(flag("help"))
.arg(flag("version").short('V'))
// First, set up primary positional/flag arguments.
.arg(arg("pattern").required_unless_eq_any(&[
.arg(arg("pattern").required_unless_present_any(&[
"file",
"files",
"help-short",

View file

@ -68,8 +68,8 @@ pub fn runner() -> Runner {
["required_if", "required_if_eq"],
["required_ifs", "required_if_eq_any"],
["required_unless", "required_unless_present"],
["required_unless_one", "required_unless_eq_any"],
["required_unless_all", "required_unless_eq_all"],
["required_unless_one", "required_unless_present_any"],
["required_unless_all", "required_unless_present_all"],
],
)
.rename_methods(

View file

@ -696,14 +696,14 @@ impl<'help> Arg<'help> {
/// * supplies *all* of the `names` arguments.
///
/// **NOTE:** If you wish for this argument to only be required if *one of* these args are
/// present see [`Arg::required_unless_eq_any`]
/// present see [`Arg::required_unless_present_any`]
///
/// # Examples
///
/// ```rust
/// # use clap::Arg;
/// Arg::new("config")
/// .required_unless_eq_all(&["cfg", "dbg"])
/// .required_unless_present_all(&["cfg", "dbg"])
/// # ;
/// ```
///
@ -714,7 +714,7 @@ impl<'help> Arg<'help> {
/// # use clap::{App, Arg};
/// let res = App::new("prog")
/// .arg(Arg::new("cfg")
/// .required_unless_eq_all(&["dbg", "infile"])
/// .required_unless_present_all(&["dbg", "infile"])
/// .takes_value(true)
/// .long("config"))
/// .arg(Arg::new("dbg")
@ -729,14 +729,14 @@ impl<'help> Arg<'help> {
/// assert!(res.is_ok());
/// ```
///
/// Setting [`Arg::required_unless_eq_all(names)`] and *not* supplying
/// Setting [`Arg::required_unless_present_all(names)`] and *not* supplying
/// either *all* of `unless` args or the `self` arg is an error.
///
/// ```rust
/// # use clap::{App, Arg, ErrorKind};
/// let res = App::new("prog")
/// .arg(Arg::new("cfg")
/// .required_unless_eq_all(&["dbg", "infile"])
/// .required_unless_present_all(&["dbg", "infile"])
/// .takes_value(true)
/// .long("config"))
/// .arg(Arg::new("dbg")
@ -751,9 +751,9 @@ impl<'help> Arg<'help> {
/// assert!(res.is_err());
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ```
/// [`Arg::required_unless_eq_any`]: ./struct.Arg.html#method.required_unless_eq_any
/// [`Arg::required_unless_eq_all(names)`]: ./struct.Arg.html#method.required_unless_eq_all
pub fn required_unless_eq_all<T, I>(mut self, names: I) -> Self
/// [`Arg::required_unless_present_any`]: ./struct.Arg.html#method.required_unless_present_any
/// [`Arg::required_unless_present_all(names)`]: ./struct.Arg.html#method.required_unless_present_all
pub fn required_unless_present_all<T, I>(mut self, names: I) -> Self
where
I: IntoIterator<Item = T>,
T: Key,
@ -773,11 +773,11 @@ impl<'help> Arg<'help> {
/// ```rust
/// # use clap::Arg;
/// Arg::new("config")
/// .required_unless_eq_all(&["cfg", "dbg"])
/// .required_unless_present_all(&["cfg", "dbg"])
/// # ;
/// ```
///
/// Setting [`Arg::required_unless_eq_any(names)`] requires that the argument be used at runtime
/// Setting [`Arg::required_unless_present_any(names)`] requires that the argument be used at runtime
/// *unless* *at least one of* the args in `names` are present. In the following example, the
/// required argument is *not* provided, but it's not an error because one the `unless` args
/// have been supplied.
@ -786,7 +786,7 @@ impl<'help> Arg<'help> {
/// # use clap::{App, Arg};
/// let res = App::new("prog")
/// .arg(Arg::new("cfg")
/// .required_unless_eq_any(&["dbg", "infile"])
/// .required_unless_present_any(&["dbg", "infile"])
/// .takes_value(true)
/// .long("config"))
/// .arg(Arg::new("dbg")
@ -801,14 +801,14 @@ impl<'help> Arg<'help> {
/// assert!(res.is_ok());
/// ```
///
/// Setting [`Arg::required_unless_eq_any(names)`] and *not* supplying *at least one of* `names`
/// Setting [`Arg::required_unless_present_any(names)`] and *not* supplying *at least one of* `names`
/// or this arg is an error.
///
/// ```rust
/// # use clap::{App, Arg, ErrorKind};
/// let res = App::new("prog")
/// .arg(Arg::new("cfg")
/// .required_unless_eq_any(&["dbg", "infile"])
/// .required_unless_present_any(&["dbg", "infile"])
/// .takes_value(true)
/// .long("config"))
/// .arg(Arg::new("dbg")
@ -824,9 +824,9 @@ impl<'help> Arg<'help> {
/// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
/// ```
/// [required]: ./struct.Arg.html#method.required
/// [`Arg::required_unless_eq_any(names)`]: ./struct.Arg.html#method.required_unless_eq_any
/// [`Arg::required_unless_eq_all`]: ./struct.Arg.html#method.required_unless_eq_all
pub fn required_unless_eq_any<T, I>(mut self, names: I) -> Self
/// [`Arg::required_unless_present_any(names)`]: ./struct.Arg.html#method.required_unless_present_any
/// [`Arg::required_unless_present_all`]: ./struct.Arg.html#method.required_unless_present_all
pub fn required_unless_present_any<T, I>(mut self, names: I) -> Self
where
I: IntoIterator<Item = T>,
T: Key,
@ -4400,9 +4400,9 @@ impl<'help> From<&'help Yaml> for Arg<'help> {
"overrides_with" => yaml_vec_or_str!(a, v, overrides_with),
"possible_values" => yaml_vec_or_str!(a, v, possible_value),
"case_insensitive" => yaml_to_bool!(a, v, case_insensitive),
"required_unless_eq_any" => yaml_vec!(a, v, required_unless_eq_any),
"required_unless_eq_all" => {
a = yaml_vec!(a, v, required_unless_eq_all);
"required_unless_present_any" => yaml_vec!(a, v, required_unless_present_any),
"required_unless_present_all" => {
a = yaml_vec!(a, v, required_unless_present_all);
a.set_mut(ArgSettings::RequiredUnlessAll);
a
}

View file

@ -252,11 +252,11 @@ fn required_unless_err() {
// REQUIRED_UNLESS_ALL
#[test]
fn required_unless_eq_all() {
fn required_unless_present_all() {
let res = App::new("unlessall")
.arg(
Arg::new("cfg")
.required_unless_eq_all(&["dbg", "infile"])
.required_unless_present_all(&["dbg", "infile"])
.takes_value(true)
.long("config"),
)
@ -276,7 +276,7 @@ fn required_unless_all_err() {
let res = App::new("unlessall")
.arg(
Arg::new("cfg")
.required_unless_eq_all(&["dbg", "infile"])
.required_unless_present_all(&["dbg", "infile"])
.takes_value(true)
.long("config"),
)
@ -291,11 +291,11 @@ fn required_unless_all_err() {
// REQUIRED_UNLESS_ONE
#[test]
fn required_unless_eq_any() {
fn required_unless_present_any() {
let res = App::new("unlessone")
.arg(
Arg::new("cfg")
.required_unless_eq_any(&["dbg", "infile"])
.required_unless_present_any(&["dbg", "infile"])
.takes_value(true)
.long("config"),
)
@ -311,12 +311,12 @@ fn required_unless_eq_any() {
#[test]
fn required_unless_any_2() {
// This tests that the required_unless_eq_any works when the second arg in the array is used
// This tests that the required_unless_present_any works when the second arg in the array is used
// instead of the first.
let res = App::new("unlessone")
.arg(
Arg::new("cfg")
.required_unless_eq_any(&["dbg", "infile"])
.required_unless_present_any(&["dbg", "infile"])
.takes_value(true)
.long("config"),
)
@ -336,7 +336,11 @@ fn required_unless_any_works_with_short() {
let res = App::new("unlessone")
.arg(Arg::new("a").conflicts_with("b").short('a'))
.arg(Arg::new("b").short('b'))
.arg(Arg::new("x").short('x').required_unless_eq_any(&["a", "b"]))
.arg(
Arg::new("x")
.short('x')
.required_unless_present_any(&["a", "b"]),
)
.try_get_matches_from(vec!["unlessone", "-a"]);
assert!(res.is_ok());
@ -347,7 +351,11 @@ fn required_unless_any_works_with_short_err() {
let res = App::new("unlessone")
.arg(Arg::new("a").conflicts_with("b").short('a'))
.arg(Arg::new("b").short('b'))
.arg(Arg::new("x").short('x').required_unless_eq_any(&["a", "b"]))
.arg(
Arg::new("x")
.short('x')
.required_unless_present_any(&["a", "b"]),
)
.try_get_matches_from(vec!["unlessone"]);
assert!(!res.is_ok());
@ -358,7 +366,7 @@ fn required_unless_any_works_without() {
let res = App::new("unlessone")
.arg(Arg::new("a").conflicts_with("b").short('a'))
.arg(Arg::new("b").short('b'))
.arg(Arg::new("x").required_unless_eq_any(&["a", "b"]))
.arg(Arg::new("x").required_unless_present_any(&["a", "b"]))
.try_get_matches_from(vec!["unlessone", "-a"]);
assert!(res.is_ok());
@ -372,7 +380,7 @@ fn required_unless_any_works_with_long() {
.arg(
Arg::new("x")
.long("x_is_the_option")
.required_unless_eq_any(&["a", "b"]),
.required_unless_present_any(&["a", "b"]),
)
.try_get_matches_from(vec!["unlessone", "-a"]);
@ -384,7 +392,7 @@ fn required_unless_any_1() {
let res = App::new("unlessone")
.arg(
Arg::new("cfg")
.required_unless_eq_any(&["dbg", "infile"])
.required_unless_present_any(&["dbg", "infile"])
.takes_value(true)
.long("config"),
)
@ -404,7 +412,7 @@ fn required_unless_any_err() {
let res = App::new("unlessone")
.arg(
Arg::new("cfg")
.required_unless_eq_any(&["dbg", "infile"])
.required_unless_present_any(&["dbg", "infile"])
.takes_value(true)
.long("config"),
)