From 36dae8ca6e39cdfd71b370fe735c3631cb2fe9cc Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Thu, 8 May 2025 23:48:05 +0100 Subject: [PATCH] refactor: Factor out read_config_template from setup as well --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 6cc3b6b..191eea2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,12 +47,16 @@ enum Action { Run, } +fn read_config_template() -> Result { + 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)))) +} + fn fill_config_template(config_template: String, args: SetupArgs) -> String { formatx!(config_template, args.api_url, args.rest_url, args.username, args.botpassword, args.oauth2_token).unwrap() } fn setup(args: SetupArgs) -> Result<(), std::io::Error> { - 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 config_template = read_config_template()?; let filled_in_config = fill_config_template(config_template, args); let path = get_bot_config_path(); std::fs::write(&path, filled_in_config)?;