Add command line argument parsing

This commit is contained in:
Xiretza 2024-02-10 13:20:13 +00:00
parent eeb2735c63
commit 03bcb4df90

View file

@ -27,6 +27,7 @@ mod server;
use std::path::Path;
use clap::Parser;
use color_eyre::Result;
use config::Config;
use tracing::{event, instrument, Level};
@ -60,14 +61,21 @@ async fn load_config(path: &str) -> Result<Config> {
Ok(toml::from_str(&content)?)
}
#[derive(Debug, Clone, Parser)]
struct Args {
/// Path to the configuration file.
#[arg(short, long, default_value = "config.toml")]
config: String,
}
#[tokio::main]
#[instrument]
async fn main() -> Result<()> {
let args = Args::parse();
init()?;
event!(Level::INFO, "Hello, world!");
let config = load_config("config.toml").await?;
let config = load_config(&args.config).await?;
tokio::spawn(server::run()).await??;