From 17e3f141aa5fb95aa16c090dfd27ca5e9660843e Mon Sep 17 00:00:00 2001 From: Kevin K Date: Sat, 25 Apr 2015 22:59:02 -0400 Subject: [PATCH] refactor(args.rs): deprecate mutually_excludes* for conflicts_with* methods --- src/args/arg.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/args/arg.rs b/src/args/arg.rs index 7fbec1ef..95774763 100644 --- a/src/args/arg.rs +++ b/src/args/arg.rs @@ -367,6 +367,8 @@ impl<'n, 'l, 'h, 'b, 'p, 'r> Arg<'n, 'l, 'h, 'b, 'p, 'r> { /// by default. Mutually exclusive rules only need to be set for one of the two /// arguments, they do not need to be set for each. /// + /// **NOTE:** This method is deprecated in favor of `conflicts_with()` + /// /// /// # Example /// @@ -391,6 +393,8 @@ impl<'n, 'l, 'h, 'b, 'p, 'r> Arg<'n, 'l, 'h, 'b, 'p, 'r> { /// by default. Mutually exclusive rules only need to be set for one of the two /// arguments, they do not need to be set for each. /// + /// **NOTE:** This method is deprecated in favor of `conflicts_with_all()` + /// /// /// # Example /// @@ -411,6 +415,57 @@ impl<'n, 'l, 'h, 'b, 'p, 'r> Arg<'n, 'l, 'h, 'b, 'p, 'r> { self } + /// Sets a mutually exclusive argument by name. I.e. when using this argument, + /// the following argument can't be present. + /// + /// **NOTE:** Mutually exclusive rules take precedence over being required + /// by default. Mutually exclusive rules only need to be set for one of the two + /// arguments, they do not need to be set for each. + /// + /// + /// # Example + /// + /// ```no_run + /// # use clap::{App, Arg}; + /// # let myprog = App::new("myprog").arg(Arg::with_name("conifg") + /// .conflicts_with("debug") + /// # ).get_matches(); + pub fn conflicts_with(mut self, name: &'b str) -> Arg<'n, 'l, 'h, 'b, 'p, 'r> { + if let Some(ref mut vec) = self.blacklist { + vec.push(name); + } else { + self.blacklist = Some(vec![name]); + } + self + } + + /// Sets mutually exclusive arguments by names. I.e. when using this argument, + /// the following argument can't be present. + /// + /// **NOTE:** Mutually exclusive rules take precedence over being required + /// by default. Mutually exclusive rules only need to be set for one of the two + /// arguments, they do not need to be set for each. + /// + /// + /// # Example + /// + /// ```no_run + /// # use clap::{App, Arg}; + /// # let myprog = App::new("myprog").arg(Arg::with_name("conifg") + /// .conflicts_with_all( + /// vec!["debug", "input"]) + /// # ).get_matches(); + pub fn conflicts_with_all(mut self, names: Vec<&'b str>) -> Arg<'n, 'l, 'h, 'b, 'p, 'r> { + if let Some(ref mut vec) = self.blacklist { + for n in names { + vec.push(n); + } + } else { + self.blacklist = Some(names); + } + self + } + /// Sets an argument by name that is required when this one is presnet I.e. when /// using this argument, the following argument *must* be present. ///