Simplify ASB initial setup signature

This commit is contained in:
Daniel Karzel 2021-05-13 13:56:40 +10:00
parent 7f8af7926d
commit cfa85e0bad
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
2 changed files with 5 additions and 9 deletions

View File

@ -180,12 +180,8 @@ pub fn read_config(config_path: PathBuf) -> Result<Result<Config, ConfigNotIniti
Ok(Ok(file)) Ok(Ok(file))
} }
pub fn initial_setup<F>(config_path: PathBuf, config_file: F, testnet: bool) -> Result<()> pub fn initial_setup(config_path: PathBuf, config: Config) -> Result<()> {
where let toml = toml::to_string(&config)?;
F: Fn(bool) -> Result<Config>,
{
let initial_config = config_file(testnet)?;
let toml = toml::to_string(&initial_config)?;
ensure_directory_exists(config_path.as_path())?; ensure_directory_exists(config_path.as_path())?;
fs::write(&config_path, toml)?; fs::write(&config_path, toml)?;
@ -352,7 +348,7 @@ mod tests {
}, },
}; };
initial_setup(config_path.clone(), |_| Ok(expected.clone()), false).unwrap(); initial_setup(config_path.clone(), expected.clone()).unwrap();
let actual = read_config(config_path).unwrap().unwrap(); let actual = read_config(config_path).unwrap().unwrap();
assert_eq!(expected, actual); assert_eq!(expected, actual);
@ -392,7 +388,7 @@ mod tests {
}, },
}; };
initial_setup(config_path.clone(), |_| Ok(expected.clone()), true).unwrap(); initial_setup(config_path.clone(), expected.clone()).unwrap();
let actual = read_config(config_path).unwrap().unwrap(); let actual = read_config(config_path).unwrap().unwrap();
assert_eq!(expected, actual); assert_eq!(expected, actual);

View File

@ -63,7 +63,7 @@ async fn main() -> Result<()> {
let config = match read_config(config_path.clone())? { let config = match read_config(config_path.clone())? {
Ok(config) => config, Ok(config) => config,
Err(ConfigNotInitialized {}) => { Err(ConfigNotInitialized {}) => {
initial_setup(config_path.clone(), query_user_for_initial_config, testnet)?; initial_setup(config_path.clone(), query_user_for_initial_config(testnet)?)?;
read_config(config_path)?.expect("after initial setup config can be read") read_config(config_path)?.expect("after initial setup config can be read")
} }
}; };