vector/
list.rs

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