mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
commit
5d0f2520f8
3 changed files with 12 additions and 15 deletions
|
@ -138,7 +138,7 @@ Kevin K. <kbknapp@gmail.com>
|
|||
tests subcommands
|
||||
|
||||
USAGE:
|
||||
\tclaptests subcmd [FLAGS] [OPTIONS] [ARGS]
|
||||
\tclaptests subcmd [FLAGS] [OPTIONS] [--] [ARGS]
|
||||
|
||||
FLAGS:
|
||||
-f, --flag tests flags
|
||||
|
|
18
src/app.rs
18
src/app.rs
|
@ -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]");
|
||||
|
@ -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()
|
||||
|
|
|
@ -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);
|
||||
|
@ -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),
|
||||
|
|
Loading…
Add table
Reference in a new issue