mod args;
mod migrations;
mod scaffold;
mod server;
mod tenants;
mod users;
use std::io::{self, Write};
use std::path::Path;
use super::error::TenancyError;
use super::pools::TenantPools;
pub async fn run(
pools: &TenantPools,
registry_url: &str,
dir: &Path,
args: impl IntoIterator<Item = String>,
) -> Result<(), TenancyError> {
let mut stdout = io::stdout();
run_with_writer(pools, registry_url, dir, args, &mut stdout).await
}
pub async fn run_with_writer<W: Write + Send>(
pools: &TenantPools,
registry_url: &str,
dir: &Path,
args: impl IntoIterator<Item = String>,
writer: &mut W,
) -> Result<(), TenancyError> {
let args: Vec<String> = args.into_iter().collect();
let cmd = args.first().map_or("", String::as_str);
match cmd {
"create-tenant" => {
tenants::create_tenant(pools, registry_url, dir, &args[1..], writer).await
}
"drop-tenant" => tenants::drop_tenant(pools, &args[1..], writer).await,
"purge-tenant" => tenants::purge_tenant(pools, &args[1..], writer).await,
"list-tenants" => tenants::list_tenants(pools, writer).await,
"migrate-tenants" => {
migrations::migrate_tenants_cmd(pools, registry_url, dir, writer).await
}
"migrate-registry" => migrations::migrate_registry_cmd(pools, dir, writer).await,
"create-operator" => users::create_operator_cmd(pools, &args[1..], writer).await,
"create-user" => users::create_user_cmd(pools, registry_url, &args[1..], writer).await,
"run-server" | "runserver" => {
server::run_server_cmd(pools, registry_url, &args[1..], writer).await
}
"init-tenancy" => migrations::init_tenancy_cmd(dir, writer),
"startapp" => scaffold::startapp_cmd(&args[1..], writer),
"migrate" => {
migrations::migrate_all_cmd(pools, registry_url, dir, &args[1..], writer).await
}
_ => rustango::migrate::manage::run_with_writer(
pools.registry(),
dir,
args,
writer,
)
.await
.map_err(TenancyError::Migrate),
}
}