From 91d2904599bd602deef2e515dfc65dc2863bdea0 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Mon, 13 Apr 2015 18:00:55 -0400 Subject: [PATCH 1/2] fix(from_usage): trim all whitespace before parsing --- src/app.rs | 2 +- src/usageparser.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app.rs b/src/app.rs index 8025bdcf..10a11e9f 100644 --- a/src/app.rs +++ b/src/app.rs @@ -396,7 +396,7 @@ impl<'a, 'v, 'ab, 'u, 'ar> App<'a, 'v, 'ab, 'u, 'ar>{ /// ``` pub fn args_from_usage(mut self, usage: &'ar str) -> App<'a, 'v, 'ab, 'u, 'ar> { for l in usage.lines() { - self = self.arg(Arg::from_usage(l)); + self = self.arg(Arg::from_usage(l.trim())); } self } diff --git a/src/usageparser.rs b/src/usageparser.rs index bfe29079..1ed0fe22 100644 --- a/src/usageparser.rs +++ b/src/usageparser.rs @@ -123,4 +123,4 @@ impl<'u> Iterator for UsageParser<'u> { } } } -} \ No newline at end of file +} From 09497c916b2d5dd4724f2cd0477ef6650e6d3d08 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Mon, 13 Apr 2015 18:08:25 -0400 Subject: [PATCH 2/2] docs(clap): improve readability of examples with App::args_from_usage() --- README.md | 6 +++--- clap-tests/src/main.rs | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cddde737..e7b064c7 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,9 @@ fn main() { .author("Kevin K. ") .about("Does awesome things") .args_from_usage( -"-c --config=[CONFIG] 'Sets a custom config file' - 'Sets the input file to use' -[debug]... -d 'Sets the level of debugging information'") + "-c --config=[CONFIG] 'Sets a custom config file' + 'Sets the input file to use' + [debug]... -d 'Sets the level of debugging information'") .subcommand(SubCommand::new("test") .about("controls testing features") .version("1.3") diff --git a/clap-tests/src/main.rs b/clap-tests/src/main.rs index d6cdd4bb..20b2948d 100644 --- a/clap-tests/src/main.rs +++ b/clap-tests/src/main.rs @@ -3,10 +3,9 @@ extern crate clap; use clap::{App, Arg, SubCommand}; fn main() { - let args = -"-f --flag... 'tests flags' --o --option=[opt]... 'tests options' -[positional] 'tests positionals'"; + let args = "-f --flag... 'tests flags' + -o --option=[opt]... 'tests options' + [positional] 'tests positionals'"; // Test version from Cargo.toml let version = format!("{}.{}.{}{}", env!("CARGO_PKG_VERSION_MAJOR"),