refactor: new directory structure where the flake module lives in a directory with the template in a subdirectory

This commit is contained in:
2026-04-26 18:40:32 -05:00
parent 36ac1b58d6
commit fbaed7851b
11 changed files with 2 additions and 2 deletions
+69
View File
@@ -0,0 +1,69 @@
use std::path::Path;
use clap::Parser;
use figment::{
Figment,
providers::{Env, Format, Json, Toml},
};
use tracing::{Level, event};
mod args;
use crate::args::{ActionType, ArgsError, CommandArgs};
mod config;
mod error;
use crate::error::CommandError;
#[tokio::main]
async fn main() -> Result<(), CommandError> {
let args = CommandArgs::parse();
let figment = Figment::new()
.admerge(Json::file("config.json"))
.admerge(Toml::file("config.toml"));
let config: config::CommandConfig = match &args.config {
None => figment,
Some(f) => {
let file = Path::new(&f);
match file.extension().and_then(|e| e.to_str()) {
Some("toml") => Ok(figment.admerge(Toml::file(file))),
Some("json") => Ok(figment.admerge(Json::file(file))),
_ => Err(ArgsError::InvalidConfigExtension(
file.extension().and_then(|e| e.to_str().map(String::from)),
)),
}
}?,
}
.admerge(Env::prefixed("APP_"))
.extract()?;
match &args.action {
ActionType::Serve(serve_args) => {
tracing_subscriber::fmt()
.with_max_level(serve_args.log_level)
.init();
event!(Level::ERROR, "error");
event!(Level::WARN, "warn");
event!(Level::INFO, "info");
event!(Level::DEBUG, "debug");
event!(Level::TRACE, "trace");
println!("{:#?}", args);
println!("{:#?}", config);
println!("{:#?}", config.port.ports);
}
};
println!(
"{}",
CommandError::InvalidArgument(ArgsError::InvalidConfigExtension(Some(String::from("txt"))))
);
Ok(())
}