Skip to content

Commit

Permalink
refactor(error): Clarify distinct suggestion cases
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Oct 13, 2022
1 parent 5275660 commit 63eec40
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,17 +670,24 @@ impl<F: ErrorFormatter> Error<F> {
err = err
.insert_context_unchecked(ContextKind::Usage, ContextValue::StyledStr(usage));
}
if let Some((flag, sub)) = did_you_mean {
err = err.insert_context_unchecked(
ContextKind::SuggestedArg,
ContextValue::String(format!("--{}", flag)),
);
if let Some(sub) = sub {
match did_you_mean {
Some((flag, Some(sub))) => {
err = err.insert_context_unchecked(
ContextKind::SuggestedSubcommand,
ContextValue::String(sub),
);
err = err.insert_context_unchecked(
ContextKind::SuggestedArg,
ContextValue::String(format!("--{}", flag)),
);
}
Some((flag, None)) => {
err = err.insert_context_unchecked(
ContextKind::SuggestedArg,
ContextValue::String(format!("--{}", flag)),
);
}
None => {}
}
if !suggestions.is_empty() {
err = err.insert_context_unchecked(
Expand Down

0 comments on commit 63eec40

Please sign in to comment.