Implemented cli args

This commit is contained in:
2024-03-23 22:28:03 +02:00
parent d22d3a71c8
commit 46e3eea247
5 changed files with 152 additions and 4 deletions

18
src/cli.rs Normal file
View File

@@ -0,0 +1,18 @@
use clap::Parser;
#[derive(Debug, Clone, Parser)]
#[command(version, about, long_about = None)]
pub struct CliArgs {
/// Port to bind to
#[arg(short, long, default_value_t=8080)]
pub port: u16,
/// Host ip to bind to, usually not required to change
#[arg(short, long, default_value="0.0.0.0")]
pub host: String,
/// Extra debugging output
#[arg(long, short)]
pub debug: bool
}

View File

@@ -1,17 +1,24 @@
use simplelog::*;
use crate::cli::CliArgs;
pub fn init_logger() {
pub fn init_logger(cli: &CliArgs) {
// TODO: figure out what these do
let config = ConfigBuilder::new()
.build();
let level = if cli.debug {
LevelFilter::Debug
} else {
LevelFilter::Info
};
CombinedLogger::init(
vec![
TermLogger::new(LevelFilter::Debug, config, TerminalMode::Mixed, ColorChoice::Auto),
TermLogger::new(level, config, TerminalMode::Mixed, ColorChoice::Auto),
// TODO: Set up loggin to file
// WriteLogger::new(LevelFilter::Info, Config::default(), File::create("my_rust_binary.log").unwrap()),
]

View File

@@ -1,9 +1,14 @@
use clap::Parser;
mod public;
mod logger;
mod cli;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
logger::init_logger();
let cli = cli::CliArgs::parse();
logger::init_logger(&cli);
if let Err(e) = public::start_actix().await {
log::error!("Actix had an error: {e}");