mirror of
https://github.com/clap-rs/clap
synced 2024-12-15 07:12:32 +00:00
Clearer error processing
This commit is contained in:
parent
8f4c26fc58
commit
c6bcfe819e
1 changed files with 34 additions and 35 deletions
|
@ -592,41 +592,40 @@ impl<'help, 'app> Parser<'help, 'app> {
|
||||||
self.app.color(),
|
self.app.color(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
let cands = suggestions::did_you_mean(
|
let cands = suggestions::did_you_mean(
|
||||||
&arg_os.to_string_lossy(),
|
&arg_os.to_string_lossy(),
|
||||||
self.app.all_subcommand_names(),
|
self.app.all_subcommand_names(),
|
||||||
);
|
);
|
||||||
// If the argument looks like a subcommand.
|
// If the argument looks like a subcommand.
|
||||||
if !cands.is_empty() {
|
if !cands.is_empty() {
|
||||||
let cands: Vec<_> =
|
let cands: Vec<_> =
|
||||||
cands.iter().map(|cand| format!("'{}'", cand)).collect();
|
cands.iter().map(|cand| format!("'{}'", cand)).collect();
|
||||||
return Err(ClapError::invalid_subcommand(
|
return Err(ClapError::invalid_subcommand(
|
||||||
arg_os.to_string_lossy().to_string(),
|
arg_os.to_string_lossy().to_string(),
|
||||||
cands.join(" or "),
|
cands.join(" or "),
|
||||||
self.app
|
self.app
|
||||||
.bin_name
|
.bin_name
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap_or(&self.app.name)
|
.unwrap_or(&self.app.name)
|
||||||
.to_string(),
|
.to_string(),
|
||||||
Usage::new(self).create_usage_with_title(&[]),
|
Usage::new(self).create_usage_with_title(&[]),
|
||||||
self.app.color(),
|
self.app.color(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
// If the argument must be a subcommand.
|
// If the argument must be a subcommand.
|
||||||
if !self.has_args()
|
if !self.has_args()
|
||||||
|| self.is_set(AS::InferSubcommands) && self.has_subcommands()
|
|| self.is_set(AS::InferSubcommands) && self.has_subcommands()
|
||||||
{
|
{
|
||||||
return Err(ClapError::unrecognized_subcommand(
|
return Err(ClapError::unrecognized_subcommand(
|
||||||
arg_os.to_string_lossy().to_string(),
|
arg_os.to_string_lossy().to_string(),
|
||||||
self.app
|
self.app
|
||||||
.bin_name
|
.bin_name
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap_or(&self.app.name)
|
.unwrap_or(&self.app.name)
|
||||||
.to_string(),
|
.to_string(),
|
||||||
self.app.color(),
|
self.app.color(),
|
||||||
));
|
));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Err(ClapError::unknown_argument(
|
return Err(ClapError::unknown_argument(
|
||||||
arg_os.to_string_lossy().to_string(),
|
arg_os.to_string_lossy().to_string(),
|
||||||
|
|
Loading…
Reference in a new issue