WIP: Create command structure
This commit is contained in:
parent
094970fb75
commit
77f7085d2b
File diff suppressed because it is too large
Load Diff
10
Cargo.toml
10
Cargo.toml
|
@ -4,3 +4,13 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.82"
|
||||
clap = { version = "4.5.4", features = ["derive"] }
|
||||
mysql = "25.0.0"
|
||||
serde = "1.0.198"
|
||||
toml = "0.8.12"
|
||||
|
||||
[[bin]]
|
||||
name = "mysqladm"
|
||||
bench = false
|
||||
path = "src/main.rs"
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
(toolchain.withComponents [
|
||||
"cargo" "rustc" "rustfmt" "clippy"
|
||||
])
|
||||
pkgs.openssl
|
||||
pkgs.pkg-config
|
||||
];
|
||||
RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/";
|
||||
});
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct DatabaseArgs {
|
||||
#[clap(subcommand)]
|
||||
subcmd: DatabaseCommand,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
enum DatabaseCommand {
|
||||
/// Create the DATABASE(S).
|
||||
Create,
|
||||
|
||||
/// Delete the DATABASE(S).
|
||||
Drop,
|
||||
|
||||
/// Give information about the DATABASE(S), or, if none are given, all the ones you own.
|
||||
Show,
|
||||
|
||||
/// Change permissions for the DATABASE(S).
|
||||
/// Your favorite editor will be started, allowing you to make changes to the permission table.
|
||||
/// Run `mysql-dbadm --help-editperm` for more information.
|
||||
EditPerm,
|
||||
}
|
||||
|
||||
pub fn handle_command(args: DatabaseArgs) {
|
||||
match args.subcmd {
|
||||
DatabaseCommand::Create => println!("Creating database"),
|
||||
DatabaseCommand::Drop => println!("Dropping database"),
|
||||
DatabaseCommand::Show => println!("Showing database"),
|
||||
DatabaseCommand::EditPerm => println!("Editing permissions"),
|
||||
}
|
||||
}
|
62
src/main.rs
62
src/main.rs
|
@ -1,3 +1,61 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use clap::Parser;
|
||||
|
||||
mod database_command;
|
||||
mod user_command;
|
||||
|
||||
#[derive(Parser)]
|
||||
struct Args {
|
||||
#[clap(subcommand)]
|
||||
command: Command,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
enum Command {
|
||||
/// Create, drop or edit permission for the DATABASE(s),
|
||||
#[clap(name = "db")]
|
||||
Database(database_command::DatabaseArgs),
|
||||
|
||||
/// Create, delete or change password for your USER,
|
||||
#[clap(name = "user")]
|
||||
User(user_command::UserArgs),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Args = Args::parse();
|
||||
match args.command {
|
||||
Command::Database(database_args) => database_command::handle_command(database_args),
|
||||
Command::User(user_args) => user_command::handle_command(user_args),
|
||||
}
|
||||
}
|
||||
|
||||
// loginstud03% mysql-dbadm --help
|
||||
|
||||
// Usage: mysql-dbadm COMMAND [DATABASE]...
|
||||
// Create, drop og edit permission for the DATABASE(s),
|
||||
// as determined by the COMMAND. Valid COMMANDs:
|
||||
|
||||
// create create the DATABASE(s).
|
||||
// drop delete the DATABASE(s).
|
||||
// show give information about the DATABASE(s), or, if
|
||||
// none are given, all the ones you own.
|
||||
// editperm change permissions for the DATABASE(s). Your
|
||||
// favorite editor will be started, allowing you
|
||||
// to make changes to the permission table.
|
||||
// Run 'mysql-dbadm --help-editperm' for more
|
||||
// information.
|
||||
|
||||
// Report bugs to orakel@ntnu.no
|
||||
|
||||
// loginstud03% mysql-useradm --help
|
||||
|
||||
// Usage: mysql-useradm COMMAND [USER]...
|
||||
// Create, delete or change password for the USER(s),
|
||||
// as determined by the COMMAND. Valid COMMANDs:
|
||||
|
||||
// create create the USER(s).
|
||||
// delete delete the USER(s).
|
||||
// passwd change the MySQL password for the USER(s).
|
||||
// show give information about the USERS(s), or, if
|
||||
// none are given, all the users you have.
|
||||
|
||||
// Report bugs to orakel@ntnu.no
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
use clap::Parser;
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct UserArgs {
|
||||
#[clap(subcommand)]
|
||||
subcmd: UserCommand,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
enum UserCommand {
|
||||
Create,
|
||||
Delete,
|
||||
Passwd,
|
||||
Show,
|
||||
}
|
||||
|
||||
pub fn handle_command(args: UserArgs) {
|
||||
match args.subcmd {
|
||||
UserCommand::Create => println!("Creating user"),
|
||||
UserCommand::Delete => println!("Deleting user"),
|
||||
UserCommand::Passwd => println!("Changing password"),
|
||||
UserCommand::Show => println!("Showing user"),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue