misc: initial commit

This commit is contained in:
hdbg
2025-12-03 17:28:33 +01:00
commit c20f8d6d5f
11 changed files with 3327 additions and 0 deletions

64
src/cli.rs Normal file
View File

@@ -0,0 +1,64 @@
use clap::{Args, Parser, Subcommand, builder::styling};
const STYLES: styling::Styles = styling::Styles::styled()
.header(styling::AnsiColor::Green.on_default().bold())
.usage(styling::AnsiColor::Green.on_default().bold())
.literal(styling::AnsiColor::Blue.on_default().bold())
.placeholder(styling::AnsiColor::Cyan.on_default());
#[derive(Parser)]
#[command(name = "pgx")]
#[command(about = "Project-scoped PostgreSQL instance manager", long_about = None)]
#[command(version)]
#[command(styles = STYLES)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
#[arg(short, long, global = true)]
pub verbose: bool,
}
#[derive(Clone, clap::ValueEnum)]
pub enum ConnectionFormat {
/// Human-readable text format
Text,
/// JSON format
Json,
/// Environment variable format
Env,
}
#[derive(Subcommand)]
pub enum ControlCommands {
/// Start postgres instance
Start,
/// Stop postgres instance
Stop,
/// Restart postgres instance
Restart,
/// (WARNING!) Destroy postgres instance
Destroy,
/// Status of instance
Status,
/// View logs produced by postgres
Logs { follow: bool },
/// (Sensitive) get connection details
Connection { format: ConnectionFormat },
}
#[derive(Subcommand)]
pub enum Commands {
/// Create a new project, or initialize instance for existing one
Init,
/// Create a new project, or initialize instance for existing one
Sync,
/// Start the PostgreSQL container for the current project
Instance {
// Name of the instance you want to control. Defaults to current project
name: Option<String>,
#[command(subcommand)]
cmd: ControlCommands,
},
}