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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/// Controls which optional fields appear in CLI output.
///
/// Fields can be selected via `--fields` flag (comma-separated) or configured
/// in `grapha.toml` under `[output] default_fields`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FieldSet {
pub file: bool,
pub id: bool,
pub module: bool,
pub span: bool,
pub snippet: bool,
pub visibility: bool,
pub signature: bool,
pub role: bool,
}
impl Default for FieldSet {
fn default() -> Self {
Self {
file: true,
id: false,
module: false,
span: false,
snippet: false,
visibility: false,
signature: false,
role: false,
}
}
}
impl FieldSet {
pub fn all() -> Self {
Self {
file: true,
id: true,
module: true,
span: true,
snippet: true,
visibility: true,
signature: true,
role: true,
}
}
pub fn none() -> Self {
Self {
file: false,
id: false,
module: false,
span: false,
snippet: false,
visibility: false,
signature: false,
role: false,
}
}
pub fn parse(input: &str) -> Self {
match input.trim() {
"all" => Self::all(),
"none" => Self::none(),
s => {
let mut fs = Self::none();
for field in s.split(',') {
match field.trim() {
"file" => fs.file = true,
"id" => fs.id = true,
"module" => fs.module = true,
"span" => fs.span = true,
"snippet" => fs.snippet = true,
"visibility" => fs.visibility = true,
"signature" => fs.signature = true,
"role" => fs.role = true,
_ => {}
}
}
fs
}
}
}
pub fn from_config(fields: &[String]) -> Self {
Self::parse(&fields.join(","))
}
}