From 6b6b6035ed960b7ddf7e14952cc77a9c23b47187 Mon Sep 17 00:00:00 2001 From: CreepySkeleton Date: Sun, 31 May 2020 04:39:24 +0300 Subject: [PATCH] Arg::required_unless_one => required_unless_eq_any --- src/build/arg/mod.rs | 18 +++++++++--------- tests/require.rs | 34 +++++++++++++++++----------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs index a6e5759f..1f16aa85 100644 --- a/src/build/arg/mod.rs +++ b/src/build/arg/mod.rs @@ -689,7 +689,7 @@ impl<'help> Arg<'help> { /// all these other arguments are present). /// /// **NOTE:** If you wish for this argument to only be required if *one of* these args are - /// present see [`Arg::required_unless_one`] + /// present see [`Arg::required_unless_eq_any`] /// /// # Examples /// @@ -746,7 +746,7 @@ impl<'help> Arg<'help> { /// assert!(res.is_err()); /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// ``` - /// [`Arg::required_unless_one`]: ./struct.Arg.html#method.required_unless_one + /// [`Arg::required_unless_eq_any`]: ./struct.Arg.html#method.required_unless_eq_any /// [`Arg::required_unless_all(names)`]: ./struct.Arg.html#method.required_unless_all pub fn required_unless_all(mut self, names: &[&str]) -> Self { self.r_unless.extend(names.iter().map(Id::from)); @@ -768,7 +768,7 @@ impl<'help> Arg<'help> { /// # ; /// ``` /// - /// Setting [`Arg::required_unless_one(names)`] requires that the argument be used at runtime + /// Setting [`Arg::required_unless_eq_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. @@ -777,7 +777,7 @@ impl<'help> Arg<'help> { /// # use clap::{App, Arg}; /// let res = App::new("prog") /// .arg(Arg::new("cfg") - /// .required_unless_one(&["dbg", "infile"]) + /// .required_unless_eq_any(&["dbg", "infile"]) /// .takes_value(true) /// .long("config")) /// .arg(Arg::new("dbg") @@ -792,14 +792,14 @@ impl<'help> Arg<'help> { /// assert!(res.is_ok()); /// ``` /// - /// Setting [`Arg::required_unless_one(names)`] and *not* supplying *at least one of* `names` + /// Setting [`Arg::required_unless_eq_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_one(&["dbg", "infile"]) + /// .required_unless_eq_any(&["dbg", "infile"]) /// .takes_value(true) /// .long("config")) /// .arg(Arg::new("dbg") @@ -815,9 +815,9 @@ impl<'help> Arg<'help> { /// assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument); /// ``` /// [required]: ./struct.Arg.html#method.required - /// [`Arg::required_unless_one(names)`]: ./struct.Arg.html#method.required_unless_one + /// [`Arg::required_unless_eq_any(names)`]: ./struct.Arg.html#method.required_unless_eq_any /// [`Arg::required_unless_all`]: ./struct.Arg.html#method.required_unless_all - pub fn required_unless_one(mut self, names: &[&str]) -> Self { + pub fn required_unless_eq_any(mut self, names: &[&str]) -> Self { self.r_unless.extend(names.iter().map(Id::from)); self } @@ -4323,7 +4323,7 @@ impl<'help> From<&'help Yaml> for Arg<'help> { "overrides_with" => yaml_vec_or_str!(v, a, overrides_with), "possible_values" => yaml_vec_or_str!(v, a, possible_value), "case_insensitive" => yaml_to_bool!(a, v, case_insensitive), - "required_unless_one" => yaml_vec_or_str!(v, a, required_unless), + "required_unless_eq_any" => yaml_vec_or_str!(v, a, required_unless), "required_unless_all" => { a = yaml_vec_or_str!(v, a, required_unless); a.set_mut(ArgSettings::RequiredUnlessAll); diff --git a/tests/require.rs b/tests/require.rs index df9871b2..7b3b0a1b 100644 --- a/tests/require.rs +++ b/tests/require.rs @@ -288,11 +288,11 @@ fn required_unless_all_err() { // REQUIRED_UNLESS_ONE #[test] -fn required_unless_one() { +fn required_unless_eq_any() { let res = App::new("unlessone") .arg( Arg::new("cfg") - .required_unless_one(&["dbg", "infile"]) + .required_unless_eq_any(&["dbg", "infile"]) .takes_value(true) .long("config"), ) @@ -307,13 +307,13 @@ fn required_unless_one() { } #[test] -fn required_unless_one_2() { - // This tests that the required_unless_one works when the second arg in the array is used +fn required_unless_any_2() { + // This tests that the required_unless_eq_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_one(&["dbg", "infile"]) + .required_unless_eq_any(&["dbg", "infile"]) .takes_value(true) .long("config"), ) @@ -328,48 +328,48 @@ fn required_unless_one_2() { } #[test] -fn required_unless_one_works_with_short() { +fn required_unless_any_works_with_short() { // GitHub issue: https://github.com/kbknapp/clap-rs/issues/1135 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_one(&["a", "b"])) + .arg(Arg::new("x").short('x').required_unless_eq_any(&["a", "b"])) .try_get_matches_from(vec!["unlessone", "-a"]); assert!(res.is_ok()); } #[test] -fn required_unless_one_works_with_short_err() { +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_one(&["a", "b"])) + .arg(Arg::new("x").short('x').required_unless_eq_any(&["a", "b"])) .try_get_matches_from(vec!["unlessone"]); assert!(!res.is_ok()); } #[test] -fn required_unless_one_works_without() { +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_one(&["a", "b"])) + .arg(Arg::new("x").required_unless_eq_any(&["a", "b"])) .try_get_matches_from(vec!["unlessone", "-a"]); assert!(res.is_ok()); } #[test] -fn required_unless_one_works_with_long() { +fn required_unless_any_works_with_long() { let res = App::new("unlessone") .arg(Arg::new("a").conflicts_with("b").short('a')) .arg(Arg::new("b").short('b')) .arg( Arg::new("x") .long("x_is_the_option") - .required_unless_one(&["a", "b"]), + .required_unless_eq_any(&["a", "b"]), ) .try_get_matches_from(vec!["unlessone", "-a"]); @@ -377,11 +377,11 @@ fn required_unless_one_works_with_long() { } #[test] -fn required_unless_one_1() { +fn required_unless_any_1() { let res = App::new("unlessone") .arg( Arg::new("cfg") - .required_unless_one(&["dbg", "infile"]) + .required_unless_eq_any(&["dbg", "infile"]) .takes_value(true) .long("config"), ) @@ -397,11 +397,11 @@ fn required_unless_one_1() { } #[test] -fn required_unless_one_err() { +fn required_unless_any_err() { let res = App::new("unlessone") .arg( Arg::new("cfg") - .required_unless_one(&["dbg", "infile"]) + .required_unless_eq_any(&["dbg", "infile"]) .takes_value(true) .long("config"), )