vector/
list.rs

1#![allow(missing_docs)]
2use clap::Parser;
3use serde::Serialize;
4use vector_lib::configurable::component::{
5    EnrichmentTableDescription, SinkDescription, SourceDescription, TransformDescription,
6};
7
8#[derive(Parser, Debug)]
9#[command(rename_all = "kebab-case")]
10pub struct Opts {
11    /// Format the list in an encoding scheme.
12    #[arg(long, default_value = "text")]
13    format: Format,
14}
15
16#[derive(clap::ValueEnum, Debug, Clone, PartialEq)]
17enum Format {
18    Text,
19    Json,
20    Avro,
21}
22
23#[derive(Serialize)]
24pub struct EncodedList {
25    sources: Vec<&'static str>,
26    transforms: Vec<&'static str>,
27    sinks: Vec<&'static str>,
28    enrichment_tables: Vec<&'static str>,
29}
30
31pub fn cmd(opts: &Opts) -> exitcode::ExitCode {
32    let sources = SourceDescription::types();
33    let transforms = TransformDescription::types();
34    let sinks = SinkDescription::types();
35    let enrichment_tables = EnrichmentTableDescription::types();
36
37    #[allow(clippy::print_stdout)]
38    match opts.format {
39        Format::Text => {
40            println!("Sources:");
41            for name in sources {
42                println!("- {name}");
43            }
44
45            println!("\nTransforms:");
46            for name in transforms {
47                println!("- {name}");
48            }
49
50            println!("\nSinks:");
51            for name in sinks {
52                println!("- {name}");
53            }
54
55            println!("\nEnrichment tables:");
56            for name in enrichment_tables {
57                println!("- {name}");
58            }
59        }
60        Format::Json => {
61            let list = EncodedList {
62                sources,
63                transforms,
64                sinks,
65                enrichment_tables,
66            };
67            println!("{}", serde_json::to_string(&list).unwrap());
68        }
69        Format::Avro => {
70            let list = EncodedList {
71                sources,
72                transforms,
73                sinks,
74                enrichment_tables,
75            };
76            println!("{}", serde_json::to_string(&list).unwrap());
77        }
78    }
79
80    exitcode::OK
81}