Merge pull request #71 from kbknapp/from-usage

trim whitespace before parsing on App::args_from_usage()
This commit is contained in:
Kevin K. 2015-04-13 17:12:30 -04:00
commit 36160fc47f
4 changed files with 8 additions and 9 deletions

View file

@ -70,9 +70,9 @@ fn main() {
.author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things")
.args_from_usage(
"-c --config=[CONFIG] 'Sets a custom config file'
<INPUT> 'Sets the input file to use'
[debug]... -d 'Sets the level of debugging information'")
"-c --config=[CONFIG] 'Sets a custom config file'
<INPUT> '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")

View file

@ -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"),

View file

@ -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
}

View file

@ -123,4 +123,4 @@ impl<'u> Iterator for UsageParser<'u> {
}
}
}
}
}