yggdrasil/src/dbtool/mod.rs

76 lines
2.3 KiB
Rust

/*
* Yggdrasil: Minecraft authentication server
* Copyright (C) 2023 0xf8.dev@proton.me
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use anyhow::{bail, Result};
use argparse::{List, parser::ArgumentParser, Store, StoreTrue};
use log::{debug, info};
use yggdrasil::*;
mod dump;
mod search;
mod add_account;
mod add_profile;
mod del_account;
mod del_profile;
mod attach_profile;
#[derive(Debug, Clone)]
pub struct Args {
pub command: String,
pub arguments: Vec<String>,
}
pub async fn start(db: &Database) -> Result<()> {
let mut args = Args {
command: String::new(),
arguments: vec![],
};
{
let mut parser = ArgumentParser::new();
parser.set_description("Database tool for Yggdrasil");
parser.refer(&mut args.command)
.add_argument("command", Store, "Command to run")
.required();
parser.refer(&mut args.arguments)
.add_argument("arguments", List, "Arguments for command");
parser.parse_args_or_exit();
}
match args.command.to_lowercase().as_str() {
"dump" => dump::Dump::exec(args, &db).await?,
"search" => search::Search::exec(args, &db).await?,
"addaccount" |
"add-account" => add_account::AddAccount::exec(args, &db).await?,
"addprofile" |
"add-profile" => add_profile::AddProfile::exec(args, &db).await?,
"delaccount" |
"del-account" => del_account::DelAccount::exec(args, &db).await?,
"delprofile" |
"del-profile" => del_profile::DelProfile::exec(args, &db).await?,
"attachprofile" |
"attach-profile" => attach_profile::AttachProfile::exec(args, &db).await?,
_ => bail!("Command doesn't exist")
}
Ok(())
}