Compare commits

..

No commits in common. "c3da322a90ef71f7c17f825c9a74b6dff1eb7ab8" and "1400334ce013bfdf37b0fa8cc87361003220bb9e" have entirely different histories.

2 changed files with 6 additions and 10 deletions

View File

@ -2,5 +2,4 @@
- Report that "ReadableConfig" error, which was super unhelpful and very annoying when you don't know why it's bugging. - Report that "ReadableConfig" error, which was super unhelpful and very annoying when you don't know why it's bugging.
- Find a better notation for the error-handling in read_config_template() although the custom error message is desirable, it's very bad - Find a better notation for the error-handling in read_config_template() although the custom error message is desirable, it's very bad
to have to implement it using such a ridiculously long line... to have to implement it using such a ridiculously long line...
- Look at clap feature to allow deriving an arg-group from an enum to vastly simplify the structs required for parsing - Refactor so as to allow *either* OAuth2 or password to be filled in, depending on which was entered (with preference for OAuth2).
auth method.

View File

@ -75,21 +75,18 @@ fn read_config_template() -> Result<String, std::io::Error> {
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)))) 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 create_toml_line(field_name: &str, value: &str) -> String {
format!("{} = \"{}\"\n", field_name, value)
}
fn fill_config_template(config_template: String, args: SetupArgs) -> String { fn fill_config_template(config_template: String, args: SetupArgs) -> String {
let mut filled = formatx!(config_template, args.api_url, args.rest_url, args.username).unwrap(); let mut filled = formatx!(config_template, args.api_url, args.rest_url, args.username).unwrap();
let auth_method: AuthMethod = args.auth_phrase.into(); let chosen_method: AuthMethod = args.auth_phrase.into();
match auth_method { match chosen_method {
AuthMethod::Password(password) => { AuthMethod::Password(password) => {
filled.push_str(&create_toml_line("password", &password)); filled.push_str(format!("password = \"{}\"", password).as_str());
}, },
AuthMethod::OAuth2Token(oauth2_token) => { AuthMethod::OAuth2Token(oauth2_token) => {
filled.push_str(&create_toml_line("oauth2_token", &oauth2_token)); filled.push_str(format!("oauth2_token = \"{}\"", oauth2_token).as_str());
} }
} }
filled.push('\n');
filled filled
} }