Compare commits

...

7 Commits

3 changed files with 13 additions and 5 deletions

2
TODO.md Normal file
View File

@ -0,0 +1,2 @@
# To-do
- Report that "ReadableConfig" error, which was super unhelpful and very annoying when you don't know why it's bugging.

View File

@ -4,5 +4,5 @@ rest_url = "{}"
[auth]
username = "{}"
botpassword = "{}"
oauth2_token = "{}"
password = "{}"
# oauth2_token = "{}"

View File

@ -2,6 +2,7 @@ use formatx::formatx;
use clap::{Parser, Subcommand};
use mwbot::parsoid::WikiMultinode;
const CONFIG_TEMPLATE_PATH: &'static str = "mwbot_template.toml";
const BOT_CONFIG_PATH: &'static str = "~/.config/mwbot.toml";
#[derive(Parser)]
@ -41,12 +42,17 @@ enum Action {
}
fn setup(args: SetupArgs) -> Result<(), std::io::Error> {
if let Ok(config_template) = std::fs::read_to_string("mwbot.toml") {
if let Ok(config_template) = std::fs::read_to_string(CONFIG_TEMPLATE_PATH) {
let filled_in_config = formatx!(config_template, args.api_url, args.rest_url, args.username, args.botpassword, args.oauth2_token).unwrap();
std::fs::write(shellexpand::tilde(BOT_CONFIG_PATH).into_owned(), filled_in_config).unwrap();
let path = shellexpand::tilde(BOT_CONFIG_PATH).into_owned();
std::fs::write(&path, filled_in_config).unwrap();
{
use std::os::unix::fs::PermissionsExt;
std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o600))?;
}
Ok(())
} else {
Err(std::io::Error::new(std::io::ErrorKind::NotFound, "Unable to find mwbot.toml; did you execute the script from the same directory?"))
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)))
}
}