refactor: Use Result::or to simplify setup() control flow
This commit is contained in:
parent
fa1e646f01
commit
874506a5de
@ -42,7 +42,7 @@ enum Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn setup(args: SetupArgs) -> Result<(), std::io::Error> {
|
fn setup(args: SetupArgs) -> Result<(), std::io::Error> {
|
||||||
if let Ok(config_template) = std::fs::read_to_string(CONFIG_TEMPLATE_PATH) {
|
let config_template = std::fs::read_to_string(CONFIG_TEMPLATE_PATH).or(Err(std::io::Error::new(std::io::ErrorKind::NotFound, format!("Unable to find {}; did you execute the script from the same directory?", CONFIG_TEMPLATE_PATH))))?;
|
||||||
let filled_in_config = formatx!(config_template, args.api_url, args.rest_url, args.username, args.botpassword, args.oauth2_token).unwrap();
|
let filled_in_config = formatx!(config_template, args.api_url, args.rest_url, args.username, args.botpassword, args.oauth2_token).unwrap();
|
||||||
let path = shellexpand::tilde(BOT_CONFIG_PATH).into_owned();
|
let path = shellexpand::tilde(BOT_CONFIG_PATH).into_owned();
|
||||||
std::fs::write(&path, filled_in_config).unwrap();
|
std::fs::write(&path, filled_in_config).unwrap();
|
||||||
@ -51,9 +51,6 @@ fn setup(args: SetupArgs) -> Result<(), std::io::Error> {
|
|||||||
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600))?;
|
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600))?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
|
||||||
Err(std::io::Error::new(std::io::ErrorKind::NotFound, format!("Unable to find {}; did you execute the script from the same directory?", CONFIG_TEMPLATE_PATH)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
Loading…
Reference in New Issue
Block a user