Skip to content

Commit

Permalink
imp(Usage): re-orders optional arguments and required to natural stan…
Browse files Browse the repository at this point in the history
…dard

Also renamed is '[POSITIONAL]' => '[ARGS]' to use the more standard
vernacular

Closes #147
  • Loading branch information
kbknapp committed Jul 9, 2015
1 parent 83ac35d commit dc7e1fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions clap-tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
tests clap library
USAGE:
claptests [POSITIONAL] [FLAGS] [OPTIONS] [SUBCOMMANDS]
claptests [FLAGS] [OPTIONS] [ARGS] [SUBCOMMAND]
FLAGS:
-f, --flag tests flags
Expand All @@ -29,7 +29,7 @@
--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]
Expand All @@ -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'''

Expand Down Expand Up @@ -138,7 +138,7 @@
tests subcommands
USAGE:
claptests subcmd [POSITIONAL] [FLAGS] [OPTIONS]
claptests subcmd [FLAGS] [OPTIONS] [ARGS]
FLAGS:
-f, --flag tests flags
Expand All @@ -148,7 +148,7 @@
OPTIONS:
-o, --option <scoption>... tests options
POSITIONAL ARGUMENTS:
ARGS:
scpositional tests positionals'''

_scfop = '''flag NOT present
Expand Down
16 changes: 9 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]");
}
}

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dc7e1fc

Please sign in to comment.