From 1db749e9447e4efa2af75cf00ec38945a92d94a0 Mon Sep 17 00:00:00 2001 From: Inkedstinct Date: Tue, 19 Nov 2024 10:19:17 +0100 Subject: [PATCH] feat(main) : closes #11 ; Add command-line arguments capability with skip_inventory option --- Cargo.toml | 1 + src/main.rs | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index af11455..06fc9c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,4 @@ flate2 = { version = "1.0.34", features = ["zlib"] } tar = "0.4.43" bytes = "1.8.0" subprocess = "0.2.9" +clap = { version = "4.5.21", features = ["derive"] } diff --git a/src/main.rs b/src/main.rs index 943099f..07325fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ mod ssh; use crate::jobs::Jobs; use chrono::Local; +use clap::Parser; use derive_more::Display; use env_logger::Builder; use inventories::StrOrFloat; @@ -28,7 +29,16 @@ const JOBS_FILE: &str = "jobs.yaml"; const SCRIPTS_DIRECTORY: &str = "scripts.d"; const RESULTS_DIRECTORY: &str = "results.d"; const CONFIG_FILE: &str = "config/events_by_vendor.json"; -// + +#[derive(Parser, Debug)] +#[command(version, about = "Benchmark tool for PowerAPI Framework")] +struct BenchmarkArgs { + /// Skip the scrapping against Grid5000 API refreshing node configurations + #[arg(short, long)] + skip_inventory: bool, +} + + type BenchmarkResult = Result<(), BenchmarkError>; #[derive(Error, Debug)] pub enum BenchmarkError { @@ -209,19 +219,24 @@ fn load_or_init_jobs() -> Result { #[tokio::main] async fn main() -> Result<(), BenchmarkError> { + let benchmark_args = BenchmarkArgs::parse(); + dotenv::dotenv().ok(); let log_level = env::var("LOG_LEVEL").unwrap_or_else(|_| "debug".to_string()); build_logger(&log_level).unwrap(); info!("Starting Benchmarks!"); debug!("LOG_LEVEL is : {:?}", &log_level); + + init_directories()?; let events_by_vendor = load_events_config()?; let mut jobs: Jobs = load_or_init_jobs()?; - - inventories::generate_inventory(INVENTORIES_DIRECTORY).await?; - + + if ! benchmark_args.skip_inventory { + inventories::generate_inventory(INVENTORIES_DIRECTORY).await?; + } // If we loaded existing jobs, check their status if jobs.jobs.len() != 0 { let client = reqwest::Client::builder().build()?;