feat: --timestamp flag

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
This commit is contained in:
Christina Sørensen 2024-03-29 14:35:01 +01:00
parent 74fe2a3b4a
commit 4f5e6159fe
Signed by: cafkafk
GPG key ID: 26C542FD97F965CE
2 changed files with 15 additions and 4 deletions

View file

@ -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."))
}

View file

@ -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::<String>("name") {
host_name = name.to_owned();