Add command line argument parsing
This commit is contained in:
parent
eeb2735c63
commit
03bcb4df90
1 changed files with 11 additions and 3 deletions
14
src/main.rs
14
src/main.rs
|
@ -27,6 +27,7 @@ mod server;
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use config::Config;
|
use config::Config;
|
||||||
use tracing::{event, instrument, Level};
|
use tracing::{event, instrument, Level};
|
||||||
|
@ -60,14 +61,21 @@ async fn load_config(path: &str) -> Result<Config> {
|
||||||
Ok(toml::from_str(&content)?)
|
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]
|
#[tokio::main]
|
||||||
#[instrument]
|
#[instrument]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
init()?;
|
init()?;
|
||||||
|
|
||||||
event!(Level::INFO, "Hello, world!");
|
let config = load_config(&args.config).await?;
|
||||||
|
|
||||||
let config = load_config("config.toml").await?;
|
|
||||||
|
|
||||||
tokio::spawn(server::run()).await??;
|
tokio::spawn(server::run()).await??;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue