Merge pull request #153 from kbknapp/issue-147

imp(Usage): re-orders optional arguments and required to natural stan…
This commit is contained in:
Kevin K. 2015-07-09 10:27:15 -04:00
commit 5cd9620c42
2 changed files with 14 additions and 12 deletions

View file

@ -12,7 +12,7 @@ Kevin K. <kbknapp@gmail.com>
tests clap library
USAGE:
claptests [POSITIONAL] [FLAGS] [OPTIONS] [SUBCOMMANDS]
claptests [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND]
FLAGS:
-f, --flag tests flags
@ -29,7 +29,7 @@ OPTIONS:
--long-option-2 <option2> tests long options with exclusions
-O, --Option <option3> 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 @@ _sc_dym_usage = '''error: The subcommand 'subcm' isn't valid
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 @@ Kevin K. <kbknapp@gmail.com>
tests subcommands
USAGE:
claptests subcmd [POSITIONAL] [FLAGS] [OPTIONS]
claptests subcmd [FLAGS] [OPTIONS] [ARGS]
FLAGS:
-f, --flag tests flags
@ -148,7 +148,7 @@ FLAGS:
OPTIONS:
-o, --option <scoption>... tests options
POSITIONAL ARGUMENTS:
ARGS:
scpositional tests positionals'''
_scfop = '''flag NOT present

View file

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