pub mod execute;
pub mod models;
pub mod preprocess;
pub mod reporting;
pub mod utils;
use std::sync::Arc;
use reqwest::Client;
use crate::{
models::{cli::OutputFormat, context::Global, error::AlixtError},
reporting::render::{generate_json, generate_table, generate_text},
};
pub async fn run<W: std::io::Write>(
writer: &mut W,
args: models::cli::Args,
) -> Result<(), AlixtError> {
let content = std::fs::read_to_string(args.file.ok_or(AlixtError::InternalError(
"Somehow an arg.file containing None got into run()".to_string(),
))?)?;
let plan = preprocess::parse(content)?;
#[allow(unused)]
let mut global = Global::new();
let global = Arc::new(global);
let client = Client::new();
let outcome = execute::http::execute_test(&client, plan, global).await?;
match args.mode {
OutputFormat::Text => {
generate_text(writer, outcome)?;
}
OutputFormat::Table => {
generate_table(writer, outcome)?;
}
OutputFormat::Json => {
generate_json(writer, outcome)?;
}
}
Ok(())
}