-
Notifications
You must be signed in to change notification settings - Fork 4
/
label_drop.rs
49 lines (39 loc) · 1.4 KB
/
label_drop.rs
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
// (C) Copyright 2019-2020 Hewlett Packard Enterprise Development LP
use std::env;
use prometheus_parser;
use prometheus_parser::ReturnKind;
fn main() {
let args: Vec<String> = env::args().collect();
let expr = &args[1];
let label = &args[2];
let res = prometheus_parser::parse_expr(expr);
match res {
Ok(r) => {
let return_value = r.return_value();
if let ReturnKind::Unknown(cause) = &return_value.kind {
println!("note: expression return type is unknown, result may be inaccurate");
println!(" reason: {}", cause.message);
println!(" expression: {}", cause.expression);
println!();
}
if let Some(drops) = return_value.drops(label) {
println!("label '{}' is dropped:\n", label);
if let Some(span) = drops.span {
println!("{}", expr);
println!(
"{}{}",
" ".repeat(span.start),
"-".repeat(span.end - span.start)
);
}
println!();
println!("parent expression: {}", drops.expression);
} else {
println!("label '{}' is not dropped", label);
}
}
Err(e) => {
eprintln!("error: {}", e);
}
};
}