From 4f5e6159fe2679e62dfbc400c22cf8b1737f0c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christina=20S=C3=B8rensen?= Date: Fri, 29 Mar 2024 14:35:01 +0100 Subject: [PATCH] feat: `--timestamp` flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christina Sørensen --- src/cli.rs | 7 ++++++- src/main.rs | 12 +++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 4dcaa45..0230610 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -5,7 +5,7 @@ use std::{cell::OnceCell, sync::OnceLock}; -use clap::{arg, command, crate_authors, value_parser, Arg, Command}; +use clap::{arg, command, crate_authors, value_parser, Arg, ArgAction, Command}; const DEFAULT_CACHE: &str = "cache.nixos.org"; @@ -29,5 +29,10 @@ pub fn build_cli() -> Command { .required(false) .value_parser(value_parser!(PathBuf)), ) + .arg( + arg!(--timestamp "Add timestamp to log output.") + .action(ArgAction::SetTrue) + .required(false), + ) .arg(arg!(-v --verbose ... "Verbosity level.")) } diff --git a/src/main.rs b/src/main.rs index 3112e81..e1a0bcb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,9 +51,15 @@ async fn main() -> io::Result<()> { } //pretty_env_logger::init(); - pretty_env_logger::formatted_timed_builder() - .parse_env("RUST_LOG") - .init(); + if matches.get_flag("timestamp") { + pretty_env_logger::formatted_timed_builder() + .parse_env("RUST_LOG") + .init(); + } else { + pretty_env_logger::formatted_builder() + .parse_env("RUST_LOG") + .init(); + } if let Some(name) = matches.get_one::("name") { host_name = name.to_owned();