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>") .author("Kevin K. <kbknapp@gmail.com>")
.about("Does awesome things") .about("Does awesome things")
.args_from_usage( .args_from_usage(
"-c --config=[CONFIG] 'Sets a custom config file' "-c --config=[CONFIG] 'Sets a custom config file'
<INPUT> 'Sets the input file to use' <INPUT> 'Sets the input file to use'
[debug]... -d 'Sets the level of debugging information'") [debug]... -d 'Sets the level of debugging information'")
.subcommand(SubCommand::new("test") .subcommand(SubCommand::new("test")
.about("controls testing features") .about("controls testing features")
.version("1.3") .version("1.3")

View file

@ -3,10 +3,9 @@ extern crate clap;
use clap::{App, Arg, SubCommand}; use clap::{App, Arg, SubCommand};
fn main() { fn main() {
let args = let args = "-f --flag... 'tests flags'
"-f --flag... 'tests flags' -o --option=[opt]... 'tests options'
-o --option=[opt]... 'tests options' [positional] 'tests positionals'";
[positional] 'tests positionals'";
// Test version from Cargo.toml // Test version from Cargo.toml
let version = format!("{}.{}.{}{}", let version = format!("{}.{}.{}{}",
env!("CARGO_PKG_VERSION_MAJOR"), 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> { pub fn args_from_usage(mut self, usage: &'ar str) -> App<'a, 'v, 'ab, 'u, 'ar> {
for l in usage.lines() { for l in usage.lines() {
self = self.arg(Arg::from_usage(l)); self = self.arg(Arg::from_usage(l.trim()));
} }
self self
} }