Skip to content

Commit

Permalink
Merge pull request #165 from kbknapp/fixups
Browse files Browse the repository at this point in the history
Fixups
  • Loading branch information
kbknapp committed Jul 20, 2015
2 parents 1160bd8 + fe5d95c commit 5d0f252
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion clap-tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
tests subcommands
USAGE:
\tclaptests subcmd [FLAGS] [OPTIONS] [ARGS]
\tclaptests subcmd [FLAGS] [OPTIONS] [--] [ARGS]
FLAGS:
-f, --flag tests flags
Expand Down
18 changes: 8 additions & 10 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,14 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
&& !self.opts.is_empty() && self.opts.values().any(|a| !a.required) {
usage.push_str(" [OPTIONS]");
}
// places a '--' in the usage string if there are args and options
// supporting multiple values
if !self.positionals_idx.is_empty()
&& self.opts.values().any(|a| a.multiple )
&& !self.opts.values().any(|a| a.required)
&& self.subcommands.is_empty() {
usage.push_str(" [--]")
}
if !self.positionals_idx.is_empty() && self.positionals_idx.values()
.any(|a| !a.required) {
usage.push_str(" [ARGS]");
Expand Down Expand Up @@ -1322,16 +1330,6 @@ impl<'a, 'v, 'ab, 'u, 'h, 'ar> App<'a, 'v, 'ab, 'u, 'h, 'ar>{
longest_opt = ol;
}
}
// if longest_opt == 0 {
// for ol in self.opts
// .values()
// .filter(|ref o| o.short.is_some())
// // 3='...'
// // 4='- <>'
// .map(|ref a| a.to_string().len() + if a.long.is_some() { 4 } else { 0 }) {
// if ol > longest_opt {longest_opt = ol;}
// }
// }
let mut longest_pos = 0;
for pl in self.positionals_idx
.values()
Expand Down
7 changes: 3 additions & 4 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,11 @@ macro_rules! value_t_or_exit {
Some(v) => {
match v.parse::<$t>() {
Ok(val) => val,
Err(e) => {
println!("{} '{}' isn't a valid value\n\t{}\n\n{}\n\nPlease re-run with {} for \
Err(..) => {
println!("{} '{}' isn't a valid value\n\n{}\n\nPlease re-run with {} for \
more information",
::clap::Format::Error("error:"),
::clap::Format::Warning(v.to_string()),
e,
$m.usage(),
::clap::Format::Good("--help"));
::std::process::exit(1);
Expand All @@ -306,7 +305,7 @@ macro_rules! value_t_or_exit {
match pv.parse::<$t>() {
Ok(rv) => tmp.push(rv),
Err(_) => {
println!("{} '{}' isn't a valid value\n\t{}\n\nPlease re-run with {} for more \
println!("{} '{}' isn't a valid value\n\n{}\n\nPlease re-run with {} for more \
information",
::clap::Format::Error("error:"),
::clap::Format::Warning(pv),
Expand Down

0 comments on commit 5d0f252

Please sign in to comment.