From 334af3ba7f15c0b19ea17bd0d62adfe489b8fb00 Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Tue, 30 Sep 2025 11:04:14 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(cli):=20add=20command=20line?= =?UTF-8?q?=20interface=20with=20logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - integrate clap for parsing command line arguments - add verbosity flag for logging level control - implement basic "list" subcommand structure --- src/main.rs | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index ad379d6..b679ef3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,58 @@ -fn main() { - println!("hello world"); +use clap::{Parser, Subcommand}; + +#[derive(Parser, Debug)] +#[clap(author, version, about, long_about = None)] +struct Cli { + #[clap(flatten)] + logging: clap_verbosity_flag::Verbosity, + #[command(subcommand)] + command: Option, +} + +#[derive(Subcommand, Debug)] +enum Commands { + /// List messages + #[clap(name = "list")] + List, +} + +fn main() { + let args = Cli::parse(); + + let mut logging = get_logging(args.logging.log_level_filter()); + logging.init(); + + run(args); + // match run(args) { + // Ok(_) => {} + // Err(e) => { + // if let Some(src) = e.source() { + // log::error!("{e}: {src}"); + // eprintln!("{e}: {src}"); + // } else { + // log::error!("{e}"); + // eprintln!("{e}"); + // } + // std::process::exit(101); + // } + // } +} + +fn run(args: Cli) { + if let Some(cmds) = args.command { + match cmds { + Commands::List => todo!(), + } + } + // Ok(()) +} + +fn get_logging(level: log::LevelFilter) -> env_logger::Builder { + let mut builder = env_logger::Builder::new(); + + builder.filter(None, level); + + builder.format_timestamp_secs().format_module_path(false); + + builder }