mysqladm-rs/src/main.rs

53 lines
1.4 KiB
Rust
Raw Normal View History

#[macro_use]
extern crate prettytable;
2024-04-20 04:17:16 +02:00
use clap::Parser;
mod cli;
mod core;
2024-04-20 04:17:16 +02:00
2024-04-23 00:36:06 +02:00
#[cfg(feature = "tui")]
mod tui;
2024-04-20 04:17:16 +02:00
#[derive(Parser)]
struct Args {
#[command(subcommand)]
2024-04-20 04:17:16 +02:00
command: Command,
#[command(flatten)]
config_overrides: core::config::GlobalConfigArgs,
2024-04-23 00:36:06 +02:00
#[cfg(feature = "tui")]
#[arg(short, long, alias = "tui", global = true)]
interactive: bool,
2024-04-20 04:17:16 +02:00
}
/// Database administration tool for non-admin users to manage their own MySQL databases and users.
///
/// This tool allows you to manage users and databases in MySQL.
///
/// You are only allowed to manage databases and users that are prefixed with
/// either your username, or a group that you are a member of.
2024-04-20 04:17:16 +02:00
#[derive(Parser)]
#[command(version, about, disable_help_subcommand = true)]
2024-04-20 04:17:16 +02:00
enum Command {
#[command(flatten)]
Db(cli::database_command::DatabaseCommand),
#[command(flatten)]
User(cli::user_command::UserCommand),
2024-04-20 04:17:16 +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();
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 {
Command::Db(command) => cli::database_command::handle_command(command, connection).await,
Command::User(user_args) => cli::user_command::handle_command(user_args, connection).await,
2024-04-20 04:17:16 +02:00
}
}