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
#![allow(missing_docs)]
use clap::Parser;
use serde::Serialize;

use vector_lib::configurable::component::{
    EnrichmentTableDescription, SinkDescription, SourceDescription, TransformDescription,
};

#[derive(Parser, Debug)]
#[command(rename_all = "kebab-case")]
pub struct Opts {
    /// Format the list in an encoding scheme.
    #[arg(long, default_value = "text")]
    format: Format,
}

#[derive(clap::ValueEnum, Debug, Clone, PartialEq)]
enum Format {
    Text,
    Json,
    Avro,
}

#[derive(Serialize)]
pub struct EncodedList {
    sources: Vec<&'static str>,
    transforms: Vec<&'static str>,
    sinks: Vec<&'static str>,
    enrichment_tables: Vec<&'static str>,
}

pub fn cmd(opts: &Opts) -> exitcode::ExitCode {
    let sources = SourceDescription::types();
    let transforms = TransformDescription::types();
    let sinks = SinkDescription::types();
    let enrichment_tables = EnrichmentTableDescription::types();

    #[allow(clippy::print_stdout)]
    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);
            }

            println!("\nEnrichment tables:");
            for name in enrichment_tables {
                println!("- {}", name);
            }
        }
        Format::Json => {
            let list = EncodedList {
                sources,
                transforms,
                sinks,
                enrichment_tables,
            };
            println!("{}", serde_json::to_string(&list).unwrap());
        }
        Format::Avro => {
            let list = EncodedList {
                sources,
                transforms,
                sinks,
                enrichment_tables,
            };
            println!("{}", serde_json::to_string(&list).unwrap());
        }
    }

    exitcode::OK
}