diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-11-10 08:31:24 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-11-10 08:31:33 +0100 |
commit | 596e863e92bd606458a76c3d2a5fb0da83b20dda (patch) | |
tree | f95b40c2e058443d27ac0777500e214451248eda | |
parent | 451b417f547c9c58a66847bf472e82664c87460b (diff) |
Move DB cli interface to proper place
This moves the DB CLI interface building code to src/cli.rs and the
interface handling code to src/commands/db.rs
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/cli.rs | 56 | ||||
-rw-r--r-- | src/commands/db.rs (renamed from src/db/interface.rs) | 2 | ||||
-rw-r--r-- | src/commands/mod.rs | 3 | ||||
-rw-r--r-- | src/db/cli.rs | 68 | ||||
-rw-r--r-- | src/db/mod.rs | 6 | ||||
-rw-r--r-- | src/main.rs | 2 |
6 files changed, 60 insertions, 77 deletions
@@ -60,8 +60,62 @@ pub fn cli<'a>() -> App<'a> { .help("Overwrite the database name set via configuration. Can also be overriden via environment, but this setting has presendence.") ) + .subcommand(App::new("db") + .about("Database CLI interface") + .subcommand(App::new("cli") + .about("Start a database CLI, if installed on the current host") + .long_about(indoc::indoc!(r#" + Starts a database shell on the configured database using one of the following + programs: + - psql + - pgcli - .subcommand(crate::db::cli()) + if installed. + "#)) + + .arg(Arg::with_name("tool") + .required(false) + .multiple(false) + .long("tool") + .value_name("TOOL") + .possible_values(&["psql", "pgcli"]) + .help("Use a specific tool") + ) + ) + + .subcommand(App::new("artifacts") + .about("List artifacts from the DB") + .arg(Arg::with_name("csv") + .required(false) + .multiple(false) + .long("csv") + .takes_value(false) + .help("Format output as CSV") + ) + ) + + .subcommand(App::new("envvars") + .about("List envvars from the DB") + .arg(Arg::with_name("csv") + .required(false) + .multiple(false) + .long("csv") + .takes_value(false) + .help("Format output as CSV") + ) + ) + + .subcommand(App::new("images") + .about("List images from the DB") + .arg(Arg::with_name("csv") + .required(false) + .multiple(false) + .long("csv") + .takes_value(false) + .help("Format output as CSV") + ) + ) + ) .subcommand(App::new("build") .about("Build packages in containers") diff --git a/src/db/interface.rs b/src/commands/db.rs index 1f0f544..ba85446 100644 --- a/src/db/interface.rs +++ b/src/commands/db.rs @@ -14,7 +14,7 @@ use itertools::Itertools; use crate::db::DbConnectionConfig; use crate::db::models; -pub fn interface(db_connection_config: DbConnectionConfig, matches: &ArgMatches) -> Result<()> { +pub fn db(db_connection_config: DbConnectionConfig, matches: &ArgMatches) -> Result<()> { match matches.subcommand() { ("cli", Some(matches)) => cli(db_connection_config, matches), ("artifacts", Some(matches)) => artifacts(db_connection_config, matches), diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 139f722..7118157 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,6 +1,9 @@ mod build; pub use build::build; +mod db; +pub use db::db; + mod env_of; pub use env_of::env_of; diff --git a/src/db/cli.rs b/src/db/cli.rs deleted file mode 100644 index d883bf7..0000000 --- a/src/db/cli.rs +++ /dev/null @@ -1,68 +0,0 @@ -use clap_v3 as clap; -use clap::App; -use clap::Arg; -use clap::crate_authors; -use clap::crate_version; - -pub fn cli<'a>() -> App<'a> { - App::new("db") - .author(crate_authors!()) - .version(crate_version!()) - .about("Database CLI interface") - - .subcommand(App::new("cli") - .about("Start a database CLI, if installed on the current host") - .long_about(indoc::indoc!(r#" - Starts a database shell on the configured database using one of the following - programs: - - psql - - pgcli - - if installed. - "#)) - - .arg(Arg::with_name("tool") - .required(false) - .multiple(false) - .long("tool") - .value_name("TOOL") - .possible_values(&["psql", "pgcli"]) - .help("Use a specific tool") - ) - ) - - .subcommand(App::new("artifacts") - .about("List artifacts from the DB") - .arg(Arg::with_name("csv") - .required(false) - .multiple(false) - .long("csv") - .takes_value(false) - .help("Format output as CSV") - ) - ) - - .subcommand(App::new("envvars") - .about("List envvars from the DB") - .arg(Arg::with_name("csv") - .required(false) - .multiple(false) - .long("csv") - .takes_value(false) - .help("Format output as CSV") - ) - ) - - .subcommand(App::new("images") - .about("List images from the DB") - .arg(Arg::with_name("csv") - .required(false) - .multiple(false) - .long("csv") - .takes_value(false) - .help("Format output as CSV") - ) - ) - -} - diff --git a/src/db/mod.rs b/src/db/mod.rs index f16b879..8134951 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -1,11 +1,5 @@ mod connection; pub use connection::*; -mod cli; -pub use cli::*; - -mod interface; -pub use interface::*; - pub mod models; diff --git a/src/main.rs b/src/main.rs index 45cc9dc..425ad2f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,7 @@ async fn main() -> Result<()> { let db_connection_config = crate::db::parse_db_connection_config(&config, &cli); match cli.subcommand() { - ("db", Some(matches)) => db::interface(db_connection_config, matches)?, + ("db", Some(matches)) => crate::commands::db(db_connection_config, matches)?, ("build", Some(matches)) => { let conn = crate::db::establish_connection(db_connection_config)?; |