Repository: kbknapp/clap-rs
Pull request #906 (2017-03-17 01:53:51)

Issue 903


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 81490bab..0985e1fe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,18 @@
+<a name="v2.21.2"></a>
+### v2.21.2 (2017-03-17)
+
+
+#### Improvements
+
+*   options that use `require_equals(true)` now display the equals sign in help messages, usage strings, and errors" ([c8eb0384](https://github.com/kbknapp/clap-rs/commit/c8eb0384d394d2900ccdc1593099c97808a3fa05), closes [#903](https://github.com/kbknapp/clap-rs/issues/903))
+
+
+#### Bug Fixes
+
+*  setting the max term width now correctly propagates down through child subcommands
+
+
+
 <a name="v2.21.1"></a>
 ### v2.21.1 (2017-03-12)
 
diff --git a/Cargo.toml b/Cargo.toml
index c5a226d2..85982408 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 
 name = "clap"
-version = "2.21.1"
+version = "2.21.2"
 authors = ["Kevin K. <kbknapp@gmail.com>"]
 exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"]
 repository = "https://github.com/kbknapp/clap-rs.git"
diff --git a/README.md b/README.md
index d7d17725..b8b5a70a 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,11 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
 
 ## What's New
 
+Here's the highlights for v2.21.2
+
+*   options that use `require_equals(true)` now display the equals sign in help messages, usage strings, and errors
+*  setting the max term width now correctly propagates down through child subcommands
+
 Here's the highlights for v2.21.1
 
 * fixes the precedence of this error to prioritize over other error messages
diff --git a/src/app/help.rs b/src/app/help.rs
index dab618e9..074dfc87 100644
--- a/src/app/help.rs
+++ b/src/app/help.rs
@@ -283,7 +283,13 @@ impl<'a> Help<'a> {
                 }
                 try!(color!(self, "--{}", l, good))
             }
-            try!(write!(self.writer, " "));
+
+            let sep = if arg.is_set(ArgSettings::RequireEquals) {
+                "="
+            } else {
+                " "
+            };
+            try!(write!(self.writer, "{}", sep));
         } else if let Some(l) = arg.long() {
             if arg.short().is_some() {
                 try!(write!(self.writer, ", "));
diff --git a/src/args/arg_builder/option.rs b/src/args/arg_builder/option.rs
index 91c2ee6f..342ccbdc 100644
--- a/src/args/arg_builder/option.rs
+++ b/src/args/arg_builder/option.rs
@@ -50,11 +50,16 @@ impl<'n, 'e> From<Arg<'n, 'e>> for OptBuilder<'n, 'e> {
 impl<'n, 'e> Display for OptBuilder<'n, 'e> {
     fn fmt(&self, f: &mut Formatter) -> Result {
         debugln!("OptBuilder::fmt");
+        let sep = if self.b.is_set(ArgSettings::RequireEquals) {
+            "="
+        } else {
+            " "
+        };
         // Write the name such --long or -l
         if let Some(l) = self.s.long {
-            try!(write!(f, "--{} ", l));
+            try!(write!(f, "--{}{}", l, sep));
         } else {
-            try!(write!(f, "-{} ", self.s.short.unwrap()));
+            try!(write!(f, "-{}{}", self.s.short.unwrap(), sep));
         }
 
         // Write the values such as <name1> <name2>


Test patch:
diff --git a/tests/app_settings.rs b/tests/app_settings.rs
index 7f6b3f00..c8cb90a7 100644
--- a/tests/app_settings.rs
+++ b/tests/app_settings.rs
@@ -19,6 +19,18 @@ ARGS:
     <arg2>    some
     <arg3>    some";
 
+static REQUIRE_EQUALS: &'static str = "clap-test v1.4.8
+
+USAGE:
+    clap-test --opt=<FILE>
+
+FLAGS:
+    -h, --help       Prints help information
+    -V, --version    Prints version information
+
+OPTIONS:
+    -o, --opt=<FILE>    some";
+
 static UNIFIED_HELP: &'static str = "test 1.3
 Kevin K.
 tests stuff
@@ -526,6 +538,22 @@ fn dont_collapse_args() {
     assert!(test::compare_output(app, "clap-test --help", DONT_COLLAPSE_ARGS, false));
 }
 
+#[test]
+fn require_eq() {
+    let app = App::new("clap-test")
+        .version("v1.4.8")
+        .arg(
+            Arg::with_name("opt")
+            .long("opt")
+            .short("o")
+            .required(true)
+            .require_equals(true)
+            .value_name("FILE")
+            .help("some"),
+        );
+    assert!(test::compare_output(app, "clap-test --help", REQUIRE_EQUALS, false));
+}
+
 #[test]
 fn args_negate_subcommands_one_level() {
     let res = App::new("disablehelp")
diff --git a/tests/require.rs b/tests/require.rs
index 31033ef3..9d289134 100644
--- a/tests/require.rs
+++ b/tests/require.rs
@@ -5,6 +5,14 @@ include!("../clap-test.rs");
 
 use clap::{App, Arg, ErrorKind, ArgGroup};
 
+static REQUIRE_EQUALS: &'static str = "error: The following required arguments were not provided:
+    --opt=<FILE>
+
+USAGE:
+    clap-test --opt=<FILE>
+
+For more information try --help";
+
 static MISSING_REQ: &'static str = "error: The following required arguments were not provided:
     <positional2>
     --long-option-2 <option2>
@@ -561,3 +569,19 @@ fn required_ifs_wrong_val_mult_fail() {
     assert!(res.is_err());
     assert_eq!(res.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
 }
+
+#[test]
+fn require_eq() {
+    let app = App::new("clap-test")
+        .version("v1.4.8")
+        .arg(
+            Arg::with_name("opt")
+            .long("opt")
+            .short("o")
+            .required(true)
+            .require_equals(true)
+            .value_name("FILE")
+            .help("some")
+        );
+    assert!(test::compare_output(app, "clap-test", REQUIRE_EQUALS, true));
+}
\ No newline at end of file