From 4a40c48e0e5338355f9b4adb7d0e550e56075872 Mon Sep 17 00:00:00 2001 From: Dejan Bosanac Date: Mon, 19 Jun 2023 12:54:53 +0200 Subject: [PATCH] chore: refactor file collect command --- cli/Cargo.toml | 6 +----- cli/src/collect.rs | 40 +++++++++++++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d681eea..3650725 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -19,8 +19,4 @@ exporter = { git = "https://github.com/trustification/trustification.git" } [[bin]] name = "guac" -path = "src/main.rs" - -[[bin]] -name = "collector" -path = "src/collector.rs" \ No newline at end of file +path = "src/main.rs" \ No newline at end of file diff --git a/cli/src/collect.rs b/cli/src/collect.rs index 904bcb4..fdcb318 100644 --- a/cli/src/collect.rs +++ b/cli/src/collect.rs @@ -6,24 +6,50 @@ use guac::collector::{ emitter::NatsEmitter, }; -#[derive(clap::Subcommand, Debug)] +use clap::Subcommand; + +#[derive(Subcommand, Debug)] pub enum CollectCommand { - File { path: String }, - S3 {}, + File(FileCommand), } impl CollectCommand { pub async fn run(self) -> anyhow::Result { - println!("Collecting ..."); + match self { + Self::File(command) => command.run().await, + } + } +} + +#[derive(Clone, Debug, clap::Parser)] +#[command(rename_all_env = "SCREAMING_SNAKE_CASE")] +pub struct FileConfig { + #[arg(short = 'n', long = "nats", default_value = "127.0.0.1:4222")] + pub(crate) nats_url: String, + + path: String, +} - let emitter = NatsEmitter::new("127.0.0.1:4222").await?; +#[derive(clap::Args, Debug)] +#[command( + about = "Run the file collector", + args_conflicts_with_subcommands = true +)] +pub struct FileCommand { + #[command(flatten)] + pub(crate) config: FileConfig, +} + +impl FileCommand { + pub async fn run(self) -> anyhow::Result { + println!("Collecting file {:?}", self.config.path); + let emitter = NatsEmitter::new(&self.config.nats_url).await?; let collector = FileCollector { - path: "example/seedwing-java-example.bom".to_string(), + path: self.config.path, }; collector.run(emitter).await?; - Ok(ExitCode::SUCCESS) } }