Repository: kbknapp/clap-rs
Pull request #916 (2017-03-24 03:52:33)

Usage regression
cc @BurntSushi

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/kbknapp/clap-rs/916)
<!-- Reviewable:end -->


mention-bot: @kbknapp, thanks for your PR! By analyzing the history of the files in this pull request, we identified @hgrecco, @tormol and @sru to be potential reviewers.
coveralls: 
[![Coverage Status](https://coveralls.io/builds/10751655/badge)](https://coveralls.io/builds/10751655)

Coverage increased (+0.06%) to 91.51% when pulling **ba68ce2205c96fb838c661d328ea1bd0a746f933 on usage-regression** into **cc1985b6d8f2eeff9feeff9743442dc2ca9c7271 on master**.

coveralls: 
[![Coverage Status](https://coveralls.io/builds/10751787/badge)](https://coveralls.io/builds/10751787)

Coverage increased (+0.7%) to 92.109% when pulling **ba68ce2205c96fb838c661d328ea1bd0a746f933 on usage-regression** into **cc1985b6d8f2eeff9feeff9743442dc2ca9c7271 on master**.

BurntSushi: Wow thanks @kbknapp! :-)
kbknapp: @homu r+
homu: :pushpin: Commit ba68ce2 has been approved by `kbknapp`

<!-- @homu r=kbknapp ba68ce2205c96fb838c661d328ea1bd0a746f933 -->
homu: :hourglass: Testing commit ba68ce2 with merge 81c8200...
kbknapp: Homu seems to be stuck lately

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 088c6b7d..a060ce45 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,11 @@
+<a name="v2.22.1"></a>
+### v2.22.1 (2017-03-24)
+
+
+#### Bug Fixes
+
+* **usage:**  fixes a big regression with custom usage strings ([2c41caba](https://github.com/kbknapp/clap-rs/commit/2c41caba3c7d723a2894e315d04da796b0e97759))
+
 <a name="v2.22.0"></a>
 ## v2.22.0 (2017-03-23)
 
diff --git a/Cargo.toml b/Cargo.toml
index ee7356c3..fa35b15a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 
 name = "clap"
-version = "2.22.0"
+version = "2.22.1"
 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 446629ff..0def8f68 100644
--- a/README.md
+++ b/README.md
@@ -45,13 +45,14 @@ Created by [gh-md-toc](https://github.com/ekalinin/github-markdown-toc)
 
 ## What's New
 
-Here's the highlights for v2.22.0
+Here's the highlights for v2.22.1
 
-* **App::name:**  adds the ability to change the name of the App instance after creation
-* **Arg::hide_default_value:**  adds ability to hide the default value of an argument from the help string
+* **usage:**  fixes a big regression with custom usage strings 
 
-Here's the highlights for v2.21.0 to v2.21.3
+Here's the highlights for v2.21.0 to v2.22.0
 
+* **App::name:**  adds the ability to change the name of the App instance after creation
+* **Arg::hide_default_value:**  adds ability to hide the default value of an argument from the help string
 * **yaml:**  fixes support for loading author info from yaml
 * adds fish subcommand help support
 * options that use `require_equals(true)` now display the equals sign in help messages, usage strings, and errors
diff --git a/src/app/help.rs b/src/app/help.rs
index 1c5f2152..67a4a04b 100644
--- a/src/app/help.rs
+++ b/src/app/help.rs
@@ -691,7 +691,7 @@ impl<'a> Help<'a> {
         try!(write!(self.writer,
                     "\n{}{}\n\n",
                     TAB,
-                    usage::create_help_usage(parser, true)));
+                    usage::create_usage_no_title(parser, &[])));
 
         let flags = parser.has_flags();
         let pos = parser.has_positionals();
diff --git a/src/app/usage.rs b/src/app/usage.rs
index b083ef4f..5ecf4be1 100644
--- a/src/app/usage.rs
+++ b/src/app/usage.rs
@@ -43,7 +43,7 @@ pub fn create_error_usage<'a, 'b>(p: &Parser<'a, 'b>,
 }
 
 // Creates a usage string (*without title*) if one was not provided by the user manually.
-fn create_usage_no_title(p: &Parser, used: &[&str]) -> String {
+pub fn create_usage_no_title(p: &Parser, used: &[&str]) -> String {
     debugln!("usage::create_usage_no_title;");
     if let Some(u) = p.meta.usage_str {
         String::from(&*u)


Test patch:
diff --git a/tests/help.rs b/tests/help.rs
index a3354dc5..16d5c908 100644
--- a/tests/help.rs
+++ b/tests/help.rs
@@ -136,6 +136,19 @@ OPTIONS:
     -O, --opt <opt>             tests options
     -o, --option <option>...    tests options";
 
+static RIPGREP_USAGE: &'static str = "ripgrep 0.5
+
+USAGE:
+    rg [OPTIONS] <pattern> [<path> ...]
+    rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
+    rg [OPTIONS] --files [<path> ...]
+    rg [OPTIONS] --type-list
+
+FLAGS:
+    -h, --help       Prints help information
+    -V, --version    Prints version information";
+
+
 static MULTI_SC_HELP: &'static str = "ctest-subcmd-multi 0.1
 Kevin K. <kbknapp@gmail.com>
 tests subcommands
@@ -664,6 +677,18 @@ fn issue_760() {
     assert!(test::compare_output(app, "ctest --help", ISSUE_760, false));
 }
 
+#[test]
+fn ripgrep_usage() {
+    let app = App::new("ripgrep")
+        .version("0.5")
+        .usage("rg [OPTIONS] <pattern> [<path> ...]
+    rg [OPTIONS] [-e PATTERN | -f FILE ]... [<path> ...]
+    rg [OPTIONS] --files [<path> ...]
+    rg [OPTIONS] --type-list");
+
+    assert!(test::compare_output(app, "ripgrep --help", RIPGREP_USAGE, false));
+}
+
 #[test]
 fn hidden_args() {
     let app = App::new("prog")