Skip to content

Commit

Permalink
chore: refactor file collect command
Browse files Browse the repository at this point in the history
  • Loading branch information
dejanb committed Jun 19, 2023
1 parent a8541be commit 4a40c48
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
6 changes: 1 addition & 5 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
path = "src/main.rs"
40 changes: 33 additions & 7 deletions cli/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExitCode> {
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<ExitCode> {
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)
}
}

0 comments on commit 4a40c48

Please sign in to comment.