use crate::cli::parser::GenerateArgs;
use crate::commands::base::{Command, CommandContext};
use anyhow::{Result, anyhow};
use rudof_lib::{Rudof, RudofConfig};
pub struct GenerateCommand {
args: GenerateArgs,
}
impl GenerateCommand {
pub fn new(args: GenerateArgs) -> Self {
Self { args }
}
}
impl Command for GenerateCommand {
fn name(&self) -> &'static str {
"generate"
}
fn execute(&self, _ctx: &mut CommandContext) -> Result<()> {
let runtime = tokio::runtime::Runtime::new().map_err(|e| anyhow!("Failed to create tokio runtime: {e}"))?;
runtime.block_on(async {
let rudof = Rudof::new(RudofConfig::default());
let schema_format = self.args.schema_format.into();
let result_format = self.args.result_format.into();
let mut generation = rudof
.generate_data(&self.args.schema, &schema_format, self.args.entity_count)
.with_result_generation_format(&result_format);
if let Some(seed) = self.args.seed {
generation = generation.with_seed(seed);
}
if let Some(parallel) = self.args.parallel {
generation = generation.with_parallel(parallel);
}
if let Some(output) = &self.args.common.output {
generation = generation.with_output(output);
}
generation.execute().await
})?;
Ok(())
}
}