use std::path::Path;
use clap::Parser;
use config::{self, File};
use hyperparameter::*;
#[derive(Parser)]
#[command(after_long_help=generate_params_help())]
struct CommandLineArgs {
#[arg(short = 'D', long)]
define: Vec<String>,
#[arg(short = 'C', long, default_value = "examples/cfg.toml")]
config: String,
}
fn main() {
let args = CommandLineArgs::parse();
let config_path = Path::new(&args.config);
let config = config::Config::builder()
.add_source(File::from(config_path))
.build()
.unwrap();
println!(
"param1={}\t// No scope",
get_param!(example.param1, "default".to_string())
);
with_params! { params config.param_scope();
println!("param1={}\t// cfg file scope", get_param!(example.param1, "default".to_string()));
with_params! { params ParamScope::from(&args.define);
println!("param1={}\t// cmdline args scope", get_param!(example.param1, "default".to_string(), "Example param1"));
with_params! { set example.param1= "scoped".to_string();
println!("param1={}\t// user-defined scope", get_param!(example.param1, "default".to_string()));
}
}
}
}