From 23e8ebadc78a235b7cdedf32f247431333a7cc36 Mon Sep 17 00:00:00 2001 From: Kremilly Date: Thu, 24 Oct 2024 18:47:56 -0300 Subject: [PATCH] refactor: add MySQL user and password options to command line flags --- src/args_cli.rs | 8 ++++++++ src/main.rs | 20 +++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/args_cli.rs b/src/args_cli.rs index 969c84b..16d226d 100644 --- a/src/args_cli.rs +++ b/src/args_cli.rs @@ -14,4 +14,12 @@ pub struct Flags { #[arg(short, long)] /// Backup path pub folder: Option, + + #[arg(short, long)] + /// Set MySQL password + pub password: Option, + + #[arg(short, long)] + /// Set MySQL user + pub user: Option, } diff --git a/src/main.rs b/src/main.rs index b77f7ad..3a8875c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,12 +35,18 @@ fn main() { } else { Env::get_var("BACKUP_PATH") }; + + let user = if Flags::parse().user != None { + Flags::parse().user.unwrap() + } else { + Env::get_var("DB_USER") + }; + + let password = if Flags::parse().password != None { + Flags::parse().password.unwrap() + } else { + Env::get_var("DB_PASSWORD") + }; - Dump::new( - &Env::get_var("DB_USER"), - &Env::get_var("DB_PASSWORD"), - &dbname, - &backup_path, - interval - ).make_dump(); + Dump::new(&user, &password, &dbname, &backup_path, interval).make_dump(); }