Compare commits

..

No commits in common. "cabc194158f958f5c869e93c6a15a3be9ae47018" and "c5beab75d5b068d3879fa3d5c91c365119be6c12" have entirely different histories.

View File

@ -1,3 +1,4 @@
use std::process::exit;
use std::env;
use formatx::formatx;
@ -37,32 +38,36 @@ enum Action {
},
}
fn setup() -> Result<(), std::io::Error> {
fn setup() -> Result<(), &'static str> {
if let Ok(config_template) = std::fs::read_to_string("mwbot.toml") {
let username = env::var("MW_USERNAME").expect("The .env file must have a \"MW_USERNAME\" attribute.");
let oauth2_token = env::var("MW_OAUTH2").expect("The .env file must have a \"MW_OAUTH2\" attribute.");
let botpassword: String = env::var("MW_BOTPASSWORD").expect("The .env file must have a \"MW_BOTPASSWORD\" attribute.");
let botpassword = env::var("MW_BOTPASSWORD").expect("The .env file must have a \"MW_BOTPASSWORD\" attribute.");
let filled_in_config = formatx!(config_template, username, botpassword, oauth2_token).unwrap();
std::fs::write(shellexpand::tilde("~/.config/mwbot.toml").into_owned(), filled_in_config).unwrap();
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("Unable to find mwbot.toml; did you execute the script from the same directory?")
}
}
#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
async fn main() {
dotenvy::dotenv().expect("Couldn't load .env file; please make sure to create one in the same directory as executing from!");
let cli = Cli::parse();
match cli.action {
Action::Setup => {
setup()?;
eprintln!("Successfully set up ~/.config/mwbot.toml.")
if let Err(err) = setup() {
eprintln!("{}", err);
exit(1);
} else {
eprintln!("Successfully set up ~/.config/mwbot.toml.");
}
},
Action::Run {username, botpassword, oauth2_token, api_url, rest_url} => {
let bot = mwbot::Bot::builder(api_url, rest_url)
@ -75,5 +80,4 @@ async fn main() -> Result<(), std::io::Error> {
println!("{:?}", html.as_nodes());
}
}
Ok(())
}