diff --git a/pgdog/src/cli.rs b/pgdog/src/cli.rs index 05bbbbbe..bc0227a8 100644 --- a/pgdog/src/cli.rs +++ b/pgdog/src/cli.rs @@ -56,7 +56,23 @@ pub enum Commands { }, /// Check configuration files for errors. - Configcheck, + Configcheck { + /// Path to the configuration file. + #[arg(short, long)] + config: Option, + /// Path to the users.toml file. + #[arg(short, long)] + users: Option, + }, + + Psql { + /// database to connect to + #[arg(short, long)] + database: Option, + /// user to auth with + #[arg(short, long)] + user: Option, + }, /// Copy data from source to destination cluster /// using logical replication. diff --git a/pgdog/src/main.rs b/pgdog/src/main.rs index d970dd87..d7996cf4 100644 --- a/pgdog/src/main.rs +++ b/pgdog/src/main.rs @@ -14,6 +14,7 @@ use tokio::runtime::Builder; use tracing::{error, info}; use std::process::exit; +use std::process::Command; #[cfg(not(target_env = "msvc"))] use tikv_jemallocator::Jemalloc; @@ -35,13 +36,31 @@ fn main() -> Result<(), Box> { exit(0); } - Some(Commands::Configcheck) => { - if let Err(e) = config::load(&args.config, &args.users) { - error!("{}", e); + Some(Commands::Psql { + ref database, + ref user, + }) => { + #[cfg(unix)] + { + let _output = Command::new("psql") + .args([ + "--dbname", + &database.clone().expect("Database argument expected"), + "--user", + &user.clone().expect("User argument expected"), + ]) + .spawn()? + .wait(); + } + } + + Some(Commands::Configcheck { config, users }) => { + if let Err(e) = pgdog::cli::config_check(config, users) { + error!("Configuration error: {}", e); exit(1); } - info!("✅ config valid"); + info!("✅ Configuration valid"); exit(0); }