2024-04-21 06:03:25 +02:00
|
|
|
#[macro_use]
|
|
|
|
extern crate prettytable;
|
|
|
|
|
2024-04-20 04:17:16 +02:00
|
|
|
use clap::Parser;
|
|
|
|
|
2024-04-21 06:03:25 +02:00
|
|
|
mod cli;
|
|
|
|
mod core;
|
2024-04-20 04:17:16 +02:00
|
|
|
|
|
|
|
#[derive(Parser)]
|
|
|
|
struct Args {
|
2024-04-21 06:03:25 +02:00
|
|
|
#[command(subcommand)]
|
2024-04-20 04:17:16 +02:00
|
|
|
command: Command,
|
2024-04-21 06:03:25 +02:00
|
|
|
|
|
|
|
#[command(flatten)]
|
|
|
|
config_overrides: core::config::ConfigOverrideArgs,
|
2024-04-20 04:17:16 +02:00
|
|
|
}
|
|
|
|
|
2024-04-21 06:03:25 +02:00
|
|
|
/// Database administration tool designed for non-admin users to manage their own MySQL databases and users.
|
|
|
|
/// Use `--help` for advanced usage.
|
|
|
|
///
|
|
|
|
/// This tool allows you to manage users and databases in MySQL that are prefixed with your username.
|
2024-04-20 04:17:16 +02:00
|
|
|
#[derive(Parser)]
|
2024-04-21 06:03:25 +02:00
|
|
|
#[command(version, about, disable_help_subcommand = true)]
|
2024-04-20 04:17:16 +02:00
|
|
|
enum Command {
|
2024-04-21 06:03:25 +02:00
|
|
|
/// Create, drop or show/edit permissions for DATABASE(s),
|
|
|
|
#[command(alias = "database")]
|
|
|
|
Db(cli::database_command::DatabaseArgs),
|
|
|
|
|
|
|
|
// Database(cli::database_command::DatabaseArgs),
|
|
|
|
/// Create, drop, change password for, or show your USER(s),
|
|
|
|
#[command(name = "user")]
|
|
|
|
User(cli::user_command::UserArgs),
|
2024-04-20 04:17:16 +02:00
|
|
|
}
|
|
|
|
|
2024-04-21 06:03:25 +02:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> anyhow::Result<()> {
|
|
|
|
env_logger::init();
|
2024-04-20 04:17:16 +02:00
|
|
|
let args: Args = Args::parse();
|
2024-04-21 06:03:25 +02:00
|
|
|
let config = core::config::get_config(args.config_overrides)?;
|
|
|
|
let connection = core::config::mysql_connection_from_config(config).await?;
|
|
|
|
|
2024-04-20 04:17:16 +02:00
|
|
|
match args.command {
|
2024-04-21 06:03:25 +02:00
|
|
|
Command::Db(database_args) => {
|
|
|
|
cli::database_command::handle_command(database_args, connection).await
|
|
|
|
}
|
|
|
|
Command::User(user_args) => cli::user_command::handle_command(user_args, connection).await,
|
2024-04-20 04:17:16 +02:00
|
|
|
}
|
2024-04-21 06:03:25 +02:00
|
|
|
}
|