add config file stub

This commit is contained in:
April John 2025-02-25 10:51:51 +01:00
parent 69e175c459
commit 1910e1d51a
3 changed files with 353 additions and 12 deletions

View file

@ -12,6 +12,7 @@ mod quic;
use bunt::println;
use clap::{Parser, Subcommand};
use config::{Config, Source};
use log::info;
use pman::{init_process_manager, ProcessCommand, ProcessManager};
use shadow_rs::shadow;
@ -26,9 +27,9 @@ static PMAN_SENDER: OnceLock<Sender<ProcessCommand>> = OnceLock::new();
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
/// Name of the person to greet
//#[arg(short, long)]
//name: String,
/// Config File to load
#[arg(short, long)]
config: Option<String>,
/// Number of times to greet
//#[arg(short, long, default_value_t = 1)]
@ -41,9 +42,7 @@ struct Args {
#[derive(Debug, Subcommand)]
enum Commands {
#[command(arg_required_else_help = true, about = "Start client without GUI")]
CliClient {
config_file: Option<String>
},
CliClient,
#[command(about = "List compile time backed info to audit binary")]
Shadow,
#[command(about = "Start client as GUI")]
@ -51,16 +50,38 @@ enum Commands {
Devtest,
}
fn config() -> &'static Config {
static CONFIG: OnceLock<Config> = OnceLock::new();
CONFIG.get_or_init(|| {
Config::builder()
.add_source(config::Environment::with_prefix("HAI").separator("_"))
.add_source(get_config_file_source())
.build()
.unwrap()
})
}
static CONFIG_FILE: OnceLock<Option<String>> = OnceLock::new();
fn get_config_file_source() -> impl Source {
let file = CONFIG_FILE.get();
let default_dir = dirs::config_dir().unwrap();
config::File::from_str(s, format)
}
#[tokio::main]
async fn main() {
env_logger::init();
let args = Args::parse();
CONFIG_FILE.get_or_init(|| {
args.config
});
let _ = init_process_manager();
match args.command {
Commands::CliClient { config_file } => {}
Commands::CliClient => {}
Commands::Shadow => {
bininfo::print_info();