use dbcrossbarlib::{config::Configuration, tokio_glue::BoxFuture, Context};
use futures::FutureExt;
use structopt_derive::StructOpt;
pub(crate) mod config;
pub(crate) mod count;
pub(crate) mod cp;
pub(crate) mod features;
pub(crate) mod license;
pub(crate) mod schema;
#[derive(Debug, StructOpt)]
#[structopt(
name = "dbcrossbar",
about = "Convert schemas and data between databases."
)]
pub(crate) struct Opt {
#[structopt(long = "enable-unstable")]
pub(crate) enable_unstable: bool,
#[structopt(subcommand)]
pub(crate) cmd: Command,
}
#[derive(Debug, StructOpt)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum Command {
#[structopt(name = "config")]
Config {
#[structopt(flatten)]
command: config::Opt,
},
#[structopt(name = "count")]
#[structopt(after_help = r#"EXAMPLE LOCATORS:
postgres://localhost:5432/db#table
bigquery:project:dataset.table
"#)]
Count {
#[structopt(flatten)]
command: count::Opt,
},
#[structopt(name = "cp")]
#[structopt(after_help = r#"EXAMPLE LOCATORS:
postgres://localhost:5432/db#table
bigquery:project:dataset.table
"#)]
Cp {
#[structopt(flatten)]
command: cp::Opt,
},
#[structopt(name = "features")]
Features {
#[structopt(flatten)]
command: features::Opt,
},
#[structopt(name = "license")]
License {
#[structopt(flatten)]
command: license::Opt,
},
Schema {
#[structopt(flatten)]
command: schema::Opt,
},
}
pub(crate) fn run(ctx: Context, config: Configuration, opt: Opt) -> BoxFuture<()> {
match opt.cmd {
Command::Config { command } => config::run(config, command).boxed(),
Command::Count { command } => {
count::run(ctx, config, opt.enable_unstable, command).boxed()
}
Command::Cp { command } => {
cp::run(ctx, config, opt.enable_unstable, command).boxed()
}
Command::Features { command } => {
features::run(config, opt.enable_unstable, command).boxed()
}
Command::License { command } => {
license::run(config, opt.enable_unstable, command).boxed()
}
Command::Schema { command } => {
schema::run(ctx, config, opt.enable_unstable, command).boxed()
}
}
}