Compare commits
4 Commits
1400334ce0
...
c3da322a90
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c3da322a90 | ||
![]() |
2650d1d92e | ||
![]() |
9a219d4416 | ||
![]() |
6ebd7fc11b |
3
TODO.md
3
TODO.md
@ -2,4 +2,5 @@
|
||||
- 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
|
||||
to have to implement it using such a ridiculously long line...
|
||||
- Refactor so as to allow *either* OAuth2 or password to be filled in, depending on which was entered (with preference for OAuth2).
|
||||
- Look at clap feature to allow deriving an arg-group from an enum to vastly simplify the structs required for parsing
|
||||
auth method.
|
13
src/main.rs
13
src/main.rs
@ -75,18 +75,21 @@ 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))))
|
||||
}
|
||||
|
||||
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 {
|
||||
let mut filled = formatx!(config_template, args.api_url, args.rest_url, args.username).unwrap();
|
||||
let chosen_method: AuthMethod = args.auth_phrase.into();
|
||||
match chosen_method {
|
||||
let auth_method: AuthMethod = args.auth_phrase.into();
|
||||
match auth_method {
|
||||
AuthMethod::Password(password) => {
|
||||
filled.push_str(format!("password = \"{}\"", password).as_str());
|
||||
filled.push_str(&create_toml_line("password", &password));
|
||||
},
|
||||
AuthMethod::OAuth2Token(oauth2_token) => {
|
||||
filled.push_str(format!("oauth2_token = \"{}\"", oauth2_token).as_str());
|
||||
filled.push_str(&create_toml_line("oauth2_token", &oauth2_token));
|
||||
}
|
||||
}
|
||||
filled.push('\n');
|
||||
filled
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user