feat(rust): add configuration parsing and an error type
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
use clap::Parser;
|
||||
use figment::{
|
||||
Figment,
|
||||
providers::{Env, Format, Json, Toml},
|
||||
};
|
||||
use tracing::{Level, event};
|
||||
|
||||
mod args;
|
||||
@@ -6,10 +10,19 @@ use args::{ActionType, CommandArgs};
|
||||
|
||||
mod config;
|
||||
|
||||
mod error;
|
||||
use error::CommandError;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
async fn main() -> Result<(), CommandError> {
|
||||
let args = CommandArgs::parse();
|
||||
|
||||
let config: config::CommandConfig = Figment::new()
|
||||
.admerge(Json::file("config.json"))
|
||||
.admerge(Toml::file("config.toml"))
|
||||
.admerge(Env::prefixed("APP_"))
|
||||
.extract()?;
|
||||
|
||||
match &args.action {
|
||||
ActionType::Serve(serve_args) => {
|
||||
tracing_subscriber::fmt()
|
||||
@@ -24,7 +37,11 @@ async fn main() {
|
||||
|
||||
println!("{:#?}", args);
|
||||
|
||||
// println!("{:#?}", config);
|
||||
println!("{:#?}", config);
|
||||
|
||||
println!("{:#?}", config.port.ports);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user