diff --git a/cdviz-collector/Dockerfile b/cdviz-collector/Dockerfile index 3fc207e..bb91b24 100644 --- a/cdviz-collector/Dockerfile +++ b/cdviz-collector/Dockerfile @@ -53,4 +53,6 @@ ENV \ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://127.0.0.1:4317" \ OTEL_TRACES_SAMPLER="always_off" HEALTHCHECK NONE -CMD ["/cdviz-collector"] +#see https://stackoverflow.com/questions/21553353/what-is-the-difference-between-cmd-and-entrypoint-in-a-dockerfile +ENTRYPOINT ["/cdviz-collector"] +CMD ["connect"] diff --git a/cdviz-collector/src/main.rs b/cdviz-collector/src/main.rs index 10a75a6..0bf5d39 100644 --- a/cdviz-collector/src/main.rs +++ b/cdviz-collector/src/main.rs @@ -7,7 +7,7 @@ mod sources; use std::path::PathBuf; use cdevents_sdk::CDEvent; -use clap::Parser; +use clap::{Args, Parser, Subcommand}; use clap_verbosity_flag::Verbosity; use errors::{Error, Result}; use futures::future::TryJoinAll; @@ -22,17 +22,32 @@ static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; // TODO add options (or subcommand) to `check-configuration` (regardless of enabled), `configuration-dump` (after consolidation (with filter or not enabled) and exit or not), // TODO add options to overide config from cli arguments (like from env) -#[derive(Debug, Clone, clap::Parser)] +#[derive(Debug, Clone, Parser)] pub(crate) struct Cli { + #[command(flatten)] + verbose: clap_verbosity_flag::Verbosity, + + #[command(subcommand)] + command: Commands, +} + +#[derive(Debug, Clone, Subcommand)] +enum Commands { + /// connect sources to sinks + #[command(arg_required_else_help = true)] + Connect(ConnectArgs), +} + +#[derive(Debug, Clone, Args)] +#[command(args_conflicts_with_subcommands = true)] +#[command(flatten_help = true)] +struct ConnectArgs { /// The configuration file to use. #[clap(long = "config", env("CDVIZ_COLLECTOR_CONFIG"))] config: Option, /// The directory to use as the working directory. #[clap(short = 'C', long = "directory")] directory: Option, - - #[command(flatten)] - verbose: clap_verbosity_flag::Verbosity, } type Sender = tokio::sync::broadcast::Sender; @@ -69,8 +84,6 @@ fn init_log(verbose: &Verbosity) -> Result { //TODO add garcefull shutdown //TODO use logfmt //TODO use verbosity to configure tracing & log, but allow override and finer control with RUST_LOG & CDVIZ_COLLECTOR_LOG (higher priority) -//TODO add a `enabled: bool` field as part of the config of each sources & sinks -//TODO provide default config, and default values for some config fields //TODO document the architecture and the configuration //TODO add transformers ( eg file/event info, into cdevents) for sources //TODO integrations with cloudevents (sources & sink) @@ -79,9 +92,15 @@ fn init_log(verbose: &Verbosity) -> Result { async fn main() -> Result<()> { let cli = Cli::parse(); let _guard = init_log(&cli.verbose)?; - let config = config::Config::from_file(cli.config)?; + match cli.command { + Commands::Connect(args) => connect(args).await, + } +} + +async fn connect(args: ConnectArgs) -> Result<()> { + let config = config::Config::from_file(args.config)?; - if let Some(dir) = cli.directory { + if let Some(dir) = args.directory { std::env::set_current_dir(dir)?; } diff --git a/cdviz-collector/taskfile.yaml b/cdviz-collector/taskfile.yaml index ee5ead4..ffd7787 100644 --- a/cdviz-collector/taskfile.yaml +++ b/cdviz-collector/taskfile.yaml @@ -110,7 +110,7 @@ tasks: run: cmds: - - CDVIZ_COLLECTOR__SINKS__DEBUG__ENABLED=true cargo run -- -vv --config ./examples/assets/cdviz-collector.toml --directory ./examples/assets + - CDVIZ_COLLECTOR__SINKS__DEBUG__ENABLED=true cargo run -- connect -vv --config ./examples/assets/cdviz-collector.toml --directory ./examples/assets ci: desc: set of tasks run by CI diff --git a/demos/taskfile.yaml b/demos/taskfile.yaml index 27d2748..f8c25bb 100644 --- a/demos/taskfile.yaml +++ b/demos/taskfile.yaml @@ -51,4 +51,4 @@ tasks: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "http://127.0.0.1:4317" CDVIZ_COLLECTOR__SINKS__DEBUG__ENABLED: "false" cmds: - - ../../cdviz-collector/target/debug/cdviz-collector -vv --config ./cdviz-collector.toml + - ../../cdviz-collector/target/debug/cdviz-collector connect -vv --config ./cdviz-collector.toml