From a98c8470b07ff58506f5a3a4c0b615c112986e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20K=C3=A4nner?= Date: Sun, 30 Jul 2023 14:44:44 +0200 Subject: [PATCH] make logging variable via args --- src/main.rs | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2f5a75e..e3bc7ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ -use std::{cmp::Ordering, path::Path}; +use std::{cmp::Ordering, path::Path, str::FromStr}; -use clap::Parser; +use clap::{ArgAction, Parser}; use color_eyre::eyre::Result; use icu_locid::locale; use log::{debug, error, info}; @@ -9,11 +9,26 @@ use spreadsheet_ods::{ formula::{fcellref, fcellrefa, fcellrefa_table}, write_ods, Sheet, WorkBook, }; +use stderrlog::Timestamp; +/// Takes multiple csv bom files as input and combines them into one big ods file. +/// Parts will be grouped by value, footprint and WE Part number. +/// The summary is sorted by footprint first, then value. #[derive(Parser, Debug)] struct Args { + #[arg(short, long)] + /// Silence all output + quiet: bool, + #[arg(short, long, action = ArgAction::Count)] + /// verbosity + verbose: u8, + #[arg(short, long)] + /// prepend log lines with a timestamp [none, sec, ms, ns] + timestamp: Option, + /// csv bom files exported from KiCad #[arg(required = true)] input: Vec, + /// output ods file output: String, } @@ -39,11 +54,17 @@ struct Bom { fn main() -> Result<()> { color_eyre::install()?; + let args = Args::parse(); stderrlog::new() .module(module_path!()) - .verbosity(2) + .quiet(args.quiet) + .verbosity(args.verbose as usize) + .timestamp( + args.timestamp + .map(|v| Timestamp::from_str(&v).unwrap()) + .unwrap_or(Timestamp::Off), + ) .init()?; - let args = Args::parse(); let mut boms = vec![];