mod clip;
mod commands;
mod creds;
mod engines;
mod history;
mod ini;
mod reach;
mod settings;
mod snippets;
mod sshhosts;
mod tui;
mod tunnels;
mod vias;
use clap::{Parser, Subcommand};
const AFTER: &str = concat!(
"\
Three more ways to run it (not subcommands):
esql open the toolbox (TUI): connections, passwords, tunnels
esql <name> open a saved connection (e.g. `esql prod`, or `esql pg:prod`)
esql <name> :<query> run a saved query against it (see the Snippets tab)
Anything else after a name goes straight to that client, so
`esql prod -c 'select 1'` runs psql with that query and exits.
The toolbox is where passwords, tunnels, saved queries and adding/editing
connections live.
Run `esql <command> --help` for a command's details.",
"\n\n",
env!("CARGO_PKG_REPOSITORY"),
"\ncontributors: ",
env!("CARGO_PKG_AUTHORS"),
);
const LONG_VERSION: &str = concat!(
env!("CARGO_PKG_VERSION"),
"\n",
env!("CARGO_PKG_LICENSE"),
" ",
env!("CARGO_PKG_REPOSITORY"),
"\ncontributors: ",
env!("CARGO_PKG_AUTHORS"),
);
#[derive(Parser)]
#[command(
name = "easysql",
bin_name = "esql",
version,
long_version = LONG_VERSION,
about,
after_help = AFTER
)]
struct Cli {
#[command(subcommand)]
command: Option<Cmd>,
}
#[derive(Subcommand)]
enum Cmd {
#[command(verbatim_doc_comment)]
Ls(commands::ls::Args),
#[command(name = "self", subcommand)]
Selfie(commands::selfcmd::Cmd),
#[command(external_subcommand)]
Connect(Vec<String>),
}
fn main() {
let cli = Cli::parse();
match cli.command {
None => {
if let Err(e) = tui::run() {
eprintln!("esql: {e}");
std::process::exit(1);
}
}
Some(Cmd::Ls(args)) => commands::ls::run(args),
Some(Cmd::Selfie(cmd)) => commands::selfcmd::run(cmd),
Some(Cmd::Connect(args)) => commands::connect::run(args),
}
}