From dc7e1fcea5c85d317018fb201d2a9262249131b4 Mon Sep 17 00:00:00 2001 From: Kevin K Date: Thu, 9 Jul 2015 09:51:51 -0400 Subject: [PATCH] imp(Usage): re-orders optional arguments and required to natural standard Also renamed is '[POSITIONAL]' => '[ARGS]' to use the more standard vernacular Closes #147 --- clap-tests/run_tests.py | 10 +++++----- src/app.rs | 16 +++++++++------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/clap-tests/run_tests.py b/clap-tests/run_tests.py index ae3d07a6eb4..f0f29d8ffc1 100755 --- a/clap-tests/run_tests.py +++ b/clap-tests/run_tests.py @@ -12,7 +12,7 @@ tests clap library USAGE: - claptests [POSITIONAL] [FLAGS] [OPTIONS] [SUBCOMMANDS] + claptests [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND] FLAGS: -f, --flag tests flags @@ -29,7 +29,7 @@ --long-option-2 tests long options with exclusions -O, --Option tests options with specific value sets [values: fast, slow] -POSITIONAL ARGUMENTS: +ARGS: positional tests positionals positional2 tests positionals with exclusions positional3... tests positionals with specific values [values: emacs, vi] @@ -44,7 +44,7 @@ If you received this message in error, try re-running with 'claptests -- subcm' USAGE: - claptests [POSITIONAL] [FLAGS] [OPTIONS] [SUBCOMMANDS] + claptests [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND] For more information try --help''' @@ -138,7 +138,7 @@ tests subcommands USAGE: - claptests subcmd [POSITIONAL] [FLAGS] [OPTIONS] + claptests subcmd [FLAGS] [OPTIONS] [ARGS] FLAGS: -f, --flag tests flags @@ -148,7 +148,7 @@ OPTIONS: -o, --option ... tests options -POSITIONAL ARGUMENTS: +ARGS: scpositional tests positionals''' _scfop = '''flag NOT present diff --git a/src/app.rs b/src/app.rs index c14945e2526..4c5229e9172 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1178,21 +1178,23 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ .fold(String::new(), |acc, s| { acc + &format!(" {}", s)[..] }); - usage.push_str(&req_string[..]); - if !self.positionals_idx.is_empty() && self.positionals_idx.values() - .any(|a| !a.required) { - usage.push_str(" [POSITIONAL]"); - } if !self.flags.is_empty() { usage.push_str(" [FLAGS]"); } if !self.opts.is_empty() && self.opts.values().any(|a| !a.required) { usage.push_str(" [OPTIONS]"); } + if !self.positionals_idx.is_empty() && self.positionals_idx.values() + .any(|a| !a.required) { + usage.push_str(" [ARGS]"); + } + + usage.push_str(&req_string[..]); + if !self.subcommands.is_empty() { - usage.push_str(" [SUBCOMMANDS]"); + usage.push_str(" [SUBCOMMAND]"); } } @@ -1331,7 +1333,7 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{ } if pos { println!(""); - println!("POSITIONAL ARGUMENTS:"); + println!("ARGS:"); for v in self.positionals_idx.values() { let mult = if v.multiple { 3 } else { 0 }; println!("{}{}{}{}",tab,