refactor: Use constant for ~/.config/mwbot.toml
This commit is contained in:
parent
e1856f70cd
commit
db7ce5cb7e
@ -1,8 +1,12 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use formatx::formatx;
|
use formatx::formatx;
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use mwbot::parsoid::WikiMultinode;
|
use mwbot::parsoid::WikiMultinode;
|
||||||
|
|
||||||
|
const BOT_CONFIG_PATH: &'static str = "~/.config/mwbot.toml";
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(version, about, long_about = None)]
|
#[command(version, about, long_about = None)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
@ -41,7 +45,7 @@ fn setup(action: Action) -> Result<(), std::io::Error> {
|
|||||||
Action::Run => {panic!();}
|
Action::Run => {panic!();}
|
||||||
Action::Setup { username, botpassword, oauth2_token, api_url, rest_url } => {
|
Action::Setup { username, botpassword, oauth2_token, api_url, rest_url } => {
|
||||||
let filled_in_config = formatx!(config_template, api_url, rest_url, username, botpassword, oauth2_token).unwrap();
|
let filled_in_config = formatx!(config_template, api_url, rest_url, username, botpassword, oauth2_token).unwrap();
|
||||||
std::fs::write(shellexpand::tilde("~/.config/mwbot.toml").into_owned(), filled_in_config).unwrap();
|
std::fs::write(shellexpand::tilde(BOT_CONFIG_PATH).into_owned(), filled_in_config).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -59,7 +63,7 @@ async fn main() -> Result<(), std::io::Error> {
|
|||||||
match cli.action {
|
match cli.action {
|
||||||
action @ Action::Setup {..} => {
|
action @ Action::Setup {..} => {
|
||||||
setup(action)?;
|
setup(action)?;
|
||||||
eprintln!("Successfully set up ~/.config/mwbot.toml.")
|
eprintln!("Successfully set up {BOT_CONFIG_PATH}.")
|
||||||
},
|
},
|
||||||
Action::Run => {
|
Action::Run => {
|
||||||
let bot = mwbot::Bot::from_default_config().await.unwrap();
|
let bot = mwbot::Bot::from_default_config().await.unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user