From 27652e00d019db34647d44601b3be6bf0b8dec13 Mon Sep 17 00:00:00 2001
From: Federico Lolli <federico.lolli@skywarder.eu>
Date: Wed, 20 Mar 2024 15:28:40 +0100
Subject: [PATCH] Added verbose flag (for debug traces)

---
 justfile            |  4 +---
 on-host/src/cli.rs  |  4 ++++
 on-host/src/main.rs | 12 ++++++++++--
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/justfile b/justfile
index a19e273..e49488c 100644
--- a/justfile
+++ b/justfile
@@ -1,11 +1,9 @@
-export RUST_LOG := "debug"
-
 alias hb := host-build
 alias dbs := device-build-sender
 alias dbr := device-build-receiver
 
 default:
-    ./arpist gemini.csv
+    ./arpist -v gemini.csv
 
 host-build:
     #!/bin/bash
diff --git a/on-host/src/cli.rs b/on-host/src/cli.rs
index 267efbf..9da2e5b 100644
--- a/on-host/src/cli.rs
+++ b/on-host/src/cli.rs
@@ -26,6 +26,10 @@ pub struct Cli {
     /// sending the next one
     #[clap(short, long)]
     pub sync: bool,
+
+    /// The log level
+    #[clap(short, long, default_value = "false")]
+    pub verbose: bool,
 }
 
 pub fn get_styles() -> Styles {
diff --git a/on-host/src/main.rs b/on-host/src/main.rs
index 7eb4875..49ba42d 100644
--- a/on-host/src/main.rs
+++ b/on-host/src/main.rs
@@ -25,14 +25,22 @@ use crate::{
 const ACK: u8 = 0x06;
 
 fn main() {
+    let args: Cli = Cli::parse();
+
+    let lvl = if args.verbose {
+        log::LevelFilter::Debug
+    } else {
+        log::LevelFilter::Info
+    };
+
+    // initialize logger
     simple_logger::SimpleLogger::new()
-        .with_level(log::LevelFilter::Info)
+        .with_level(lvl)
         .with_local_timestamps()
         .env()
         .init()
         .unwrap();
 
-    let args: Cli = Cli::parse();
     let mut packets = Vec::new();
 
     info!("reading from {}", args.csv_input.display());
-- 
GitLab