use crate::CommandExecute;
use owo_colors::OwoColorize;
use std::path::Path;
#[derive(clap::Args, Debug)]
#[clap(about, author)]
pub(crate) struct Pgrx {
#[clap(subcommand)]
subcommand: CargoPgrxSubCommands,
#[clap(from_global, action = ArgAction::Count)]
verbose: u8,
}
impl CommandExecute for Pgrx {
fn execute(self) -> eyre::Result<()> {
self.subcommand.execute()
}
}
#[derive(clap::Subcommand, Debug)]
enum CargoPgrxSubCommands {
Bench(super::bench::Bench),
Init(super::init::Init),
Info(super::info::Info),
Start(super::start::Start),
Stop(super::stop::Stop),
Status(super::status::Status),
New(super::new::New),
Install(super::install::Install),
Package(super::package::Package),
Schema(super::schema::Schema),
Run(super::run::Run),
Connect(super::connect::Connect),
Test(super::test::Test),
Get(super::get::Get),
Cross(super::cross::Cross),
Upgrade(super::upgrade::Upgrade),
Regress(super::regress::Regress),
}
impl CommandExecute for CargoPgrxSubCommands {
fn execute(self) -> eyre::Result<()> {
use CargoPgrxSubCommands::*;
check_for_sql_generator_binary()?;
match self {
Bench(c) => c.execute(),
Init(c) => c.execute(),
Info(c) => c.execute(),
Start(c) => c.execute(),
Stop(c) => c.execute(),
Status(c) => c.execute(),
New(c) => c.execute(),
Install(c) => c.execute(),
Package(c) => c.execute(),
Schema(c) => c.execute(),
Run(c) => c.execute(),
Connect(c) => c.execute(),
Test(c) => c.execute(),
Get(c) => c.execute(),
Cross(c) => c.execute(),
Upgrade(c) => c.execute(),
Regress(c) => c.execute(),
}
}
}
fn check_for_sql_generator_binary() -> eyre::Result<()> {
if Path::new("src/bin/sql-generator.rs").exists() {
println!("{}", "\
Found `pgrx` 0.2-0.3 series SQL generation while using `cargo-pgrx` 0.4 series.
We've updated our SQL generation method, it's much faster! Please follow the upgrading steps listed in https://github.com/pgcentralfoundation/pgrx/releases/tag/v0.4.0.
Already done that? You didn't delete `src/bin/sql-generator.rs` yet, so you're still seeing this message.\
".red().bold());
std::process::exit(1)
} else {
Ok(())
}
}