mirror of
https://seed.radicle.dev/rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE.git
synced 2026-11-28 22:10:28 +08:00
refactor: move configuration file loading into Config impl
Signed-off-by: Lars Wirzenius <liw@liw.fi>
This commit is contained in:
+11
-4
@@ -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<Self, NativeError> {
|
||||
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<Self, NativeError> {
|
||||
let file = std::fs::File::open(filename)
|
||||
|
||||
Reference in New Issue
Block a user