Parse path overload from argv or env
This commit is contained in:
parent
49535b94c4
commit
ec103e4385
|
@ -1 +1 @@
|
||||||
Subproject commit 2b4cd84d7faf49d37492c6ff5708454beea7857a
|
Subproject commit e2f8edc61742ceaba929ad472cb76359795b04fc
|
|
@ -140,18 +140,30 @@ impl Into<LevelFilter> for LogLevel {
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
// The path of the config file without the file extension
|
// The path of the config file without the file extension
|
||||||
let path = match env::var("CROSS_SEED_CONFIG") {
|
let path = {
|
||||||
Ok(path) => path,
|
let args: Vec<String> = wild::args().collect();
|
||||||
Err(_) => "config".to_string(),
|
let (_args, argv) = argmap::parse(args.iter());
|
||||||
|
|
||||||
|
match argv.get("--config-path") {
|
||||||
|
Some(path) => {
|
||||||
|
println!("config path: {:?}", path);
|
||||||
|
path.first().unwrap().clone()
|
||||||
|
},
|
||||||
|
None => match env::var("CROSS_SEED_CONFIG") {
|
||||||
|
Ok(path) => path,
|
||||||
|
Err(_) => "config.toml".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Create a command line argument `Provider` (https://docs.rs/figment/0.10.6/figment/trait.Provider.html)
|
// TODO: Create a command line argument `Provider` (https://docs.rs/figment/0.10.6/figment/trait.Provider.html)
|
||||||
// TODO: Figure out priority
|
// TODO: Figure out priority
|
||||||
|
|
||||||
// Merge the config files
|
// Merge the config files
|
||||||
let figment = Figment::new()
|
let figment = Figment::new()
|
||||||
.join(CliProvider::new())
|
.join(CliProvider::new())
|
||||||
.join(Env::prefixed("CROSS_SEED_"))
|
.join(Env::prefixed("CROSS_SEED_"))
|
||||||
.join(Toml::file(format!("{}.toml", path)));
|
.join(Toml::file(format!("{}", path)));
|
||||||
|
|
||||||
let mut config: Config = figment.extract().unwrap();
|
let mut config: Config = figment.extract().unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue