summaryrefslogblamecommitdiff
path: root/src/config.rs
blob: d28e111f020c00229ad0bf9bec106fffcc3a6574 (plain) (tree)
1
2
3
4
5
6
7
8
                       
 




                       
 


                                                          

                                                                                       

                                                                                      
 

                                 
 
use serde::Deserialize;

#[derive(Deserialize)]
pub struct Config {
    pub apikey: String,
    pub server: String,
}

impl Config {
    pub fn load() -> Result<Config, config::ConfigError> {
        let builder = config::Config::builder()
            .add_source(config::File::with_name("~/.config/webol-cli").required(false))
            .add_source(config::File::with_name("webol-cli").required(false))
            .add_source(config::Environment::with_prefix("WEBOL_CLI_").separator("_"))
            .build()?;

        builder.try_deserialize()
    }
}