Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pgdog/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,23 @@ pub enum Commands {
},

/// Check configuration files for errors.
Configcheck,
Configcheck {
/// Path to the configuration file.
#[arg(short, long)]
config: Option<PathBuf>,
/// Path to the users.toml file.
#[arg(short, long)]
users: Option<PathBuf>,
},

Psql {
/// database to connect to
#[arg(short, long)]
database: Option<String>,
/// user to auth with
#[arg(short, long)]
user: Option<String>,
},

/// Copy data from source to destination cluster
/// using logical replication.
Expand Down
27 changes: 23 additions & 4 deletions pgdog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,13 +36,31 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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);
}

Expand Down