forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.rs
More file actions
96 lines (84 loc) · 2.51 KB
/
list.rs
File metadata and controls
96 lines (84 loc) · 2.51 KB
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
87
88
89
90
91
92
93
94
95
96
use crate::config::{SinkDescription, SourceDescription, TransformDescription};
use serde::Serialize;
use std::collections::HashSet;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
#[structopt(rename_all = "kebab-case")]
pub struct Opts {
/// Format the list in an encoding scheme.
#[structopt(long, default_value = "text", possible_values = &["text", "json", "avro"])]
format: Format,
}
#[derive(Debug, Clone, PartialEq)]
enum Format {
Text,
Json,
Avro,
}
impl std::str::FromStr for Format {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"text" => Ok(Format::Text),
"json" => Ok(Format::Json),
"avro" => Ok(Format::Avro),
s => Err(format!(
"{} is not a valid option, expected `text` or `json`",
s
)),
}
}
}
#[derive(Serialize)]
pub struct EncodedList {
sources: Vec<&'static str>,
transforms: Vec<&'static str>,
sinks: Vec<&'static str>,
}
pub fn cmd(opts: &Opts) -> exitcode::ExitCode {
let mut sources = SourceDescription::types();
let mut transforms = TransformDescription::types();
let mut sinks = SinkDescription::types();
// Remove deprecated components from list
let deprecated = deprecated_components();
sources.retain(|name| !deprecated.contains(name));
transforms.retain(|name| !deprecated.contains(name));
sinks.retain(|name| !deprecated.contains(name));
match opts.format {
Format::Text => {
println!("Sources:");
for name in sources {
println!("- {}", name);
}
println!("\nTransforms:");
for name in transforms {
println!("- {}", name);
}
println!("\nSinks:");
for name in sinks {
println!("- {}", name);
}
}
Format::Json => {
let list = EncodedList {
sources,
transforms,
sinks,
};
println!("{}", serde_json::to_string(&list).unwrap());
}
Format::Avro => {
let list = EncodedList {
sources,
transforms,
sinks,
};
println!("{}", serde_json::to_string(&list).unwrap());
}
}
exitcode::OK
}
/// Returns names of all deprecated components.
fn deprecated_components() -> HashSet<&'static str> {
vec!["field_filter"].into_iter().collect()
}