1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::{
error::{CliError, CliErrorKind, Context, Result},
printer::Color,
};
pub fn wrap_cli_context(err: CliError, has_exact: bool, has_all: bool) -> Result<()> {
use CliErrorKind::*;
let e = match err.kind() {
NoMatchingItem(_) => {
if has_exact {
err.context("(hint: remove '")
.color_context(Color::Yellow, "--exact")
.context("' to allow partial matches)\n")
.context("(hint: try '")
.color_context(Color::Yellow, "seaplane formation fetch-remote")
.context("' to update remote Formation definitions)\n")
} else if has_all {
err.context("(hint: try adding '")
.color_context(Color::Yellow, "--all")
.context("' to allow partial matches)\n")
.context("(hint: try '")
.color_context(Color::Yellow, "seaplane formation fetch-remote")
.context("' to sync local definitions)\n")
} else {
err
}
}
AmbiguousItem(_) => {
if has_all {
err.context("(hint: add '")
.color_context(Color::Yellow, "--all")
.context("' operation on every match)\n")
} else {
err
}
}
_ => err,
};
Err(e)
}
pub fn no_matching_item(item: String, has_exact: bool, has_all: bool) -> Result<()> {
wrap_cli_context(CliErrorKind::NoMatchingItem(item).into_err(), has_exact, has_all)
}
pub fn ambiguous_item(item: String, has_all: bool) -> Result<()> {
wrap_cli_context(CliErrorKind::AmbiguousItem(item).into_err(), false, has_all)
}