diff --git a/src/main.rs b/src/main.rs index 3e70c88..2ecc65e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,10 +49,8 @@ fn fallible_main() -> Result<(), NativeError> { pretty_env_logger::init_custom_env("RADICLE_NATIVE_CI_LOG"); info!("radicle-native-ci starts"); - const ENV: &str = "RADICLE_NATIVE_CI"; - let config = std::env::var(ENV).map_err(|e| NativeError::GetEnv(ENV, e))?; - let config = Config::read(Path::new(&config))?; - debug!("read config: {:#?}", config); + let config = Config::load_via_env()?; + let state = &config.state; if !state.exists() { debug!("creating {}", state.display()); @@ -203,6 +201,15 @@ struct Config { } impl Config { + fn load_via_env() -> Result { + const ENV: &str = "RADICLE_NATIVE_CI"; + let filename = std::env::var(ENV).map_err(|e| NativeError::GetEnv(ENV, e))?; + let filename = Path::new(&filename); + let config = Config::read(filename)?; + debug!("configuration from {}: {:#?}", filename.display(), config); + Ok(config) + } + /// Read configuration specification from a file. fn read(filename: &Path) -> Result { let file = std::fs::File::open(filename)