mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +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(),
|
||||
));
|
||||
}
|
||||
} else {
|
||||
let cands = suggestions::did_you_mean(
|
||||
&arg_os.to_string_lossy(),
|
||||
self.app.all_subcommand_names(),
|
||||
);
|
||||
// If the argument looks like a subcommand.
|
||||
if !cands.is_empty() {
|
||||
let cands: Vec<_> =
|
||||
cands.iter().map(|cand| format!("'{}'", cand)).collect();
|
||||
return Err(ClapError::invalid_subcommand(
|
||||
arg_os.to_string_lossy().to_string(),
|
||||
cands.join(" or "),
|
||||
self.app
|
||||
.bin_name
|
||||
.as_ref()
|
||||
.unwrap_or(&self.app.name)
|
||||
.to_string(),
|
||||
Usage::new(self).create_usage_with_title(&[]),
|
||||
self.app.color(),
|
||||
));
|
||||
}
|
||||
// If the argument must be a subcommand.
|
||||
if !self.has_args()
|
||||
|| self.is_set(AS::InferSubcommands) && self.has_subcommands()
|
||||
{
|
||||
return Err(ClapError::unrecognized_subcommand(
|
||||
arg_os.to_string_lossy().to_string(),
|
||||
self.app
|
||||
.bin_name
|
||||
.as_ref()
|
||||
.unwrap_or(&self.app.name)
|
||||
.to_string(),
|
||||
self.app.color(),
|
||||
));
|
||||
}
|
||||
}
|
||||
let cands = suggestions::did_you_mean(
|
||||
&arg_os.to_string_lossy(),
|
||||
self.app.all_subcommand_names(),
|
||||
);
|
||||
// If the argument looks like a subcommand.
|
||||
if !cands.is_empty() {
|
||||
let cands: Vec<_> =
|
||||
cands.iter().map(|cand| format!("'{}'", cand)).collect();
|
||||
return Err(ClapError::invalid_subcommand(
|
||||
arg_os.to_string_lossy().to_string(),
|
||||
cands.join(" or "),
|
||||
self.app
|
||||
.bin_name
|
||||
.as_ref()
|
||||
.unwrap_or(&self.app.name)
|
||||
.to_string(),
|
||||
Usage::new(self).create_usage_with_title(&[]),
|
||||
self.app.color(),
|
||||
));
|
||||
}
|
||||
// If the argument must be a subcommand.
|
||||
if !self.has_args()
|
||||
|| self.is_set(AS::InferSubcommands) && self.has_subcommands()
|
||||
{
|
||||
return Err(ClapError::unrecognized_subcommand(
|
||||
arg_os.to_string_lossy().to_string(),
|
||||
self.app
|
||||
.bin_name
|
||||
.as_ref()
|
||||
.unwrap_or(&self.app.name)
|
||||
.to_string(),
|
||||
self.app.color(),
|
||||
));
|
||||
}
|
||||
return Err(ClapError::unknown_argument(
|
||||
arg_os.to_string_lossy().to_string(),
|
||||
|
|
Loading…
Reference in a new issue