Expand description
Library surface for user binaries to host umbral’s management subcommands.
umbral-cli ships as two artefacts. The library (this crate) exposes
dispatch — the entry point user binaries call to gain the
serve / migrate / makemigrations / inspectdb /
dumpdata / loaddata subcommands. The binary (umbral) ships as
the global scaffolding tool installed via cargo install umbral-cli, and handles startproject / startapp from outside
any project.
§Quickstart
In your project’s src/main.rs:
use umbral::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
tracing_subscriber::fmt::init();
let settings = Settings::from_env()?;
let pool = umbral::db::connect(&settings.database_url).await?;
let app = App::builder()
.settings(settings)
.database("default", pool)
.model::<Article>()
.build_deferred()?;
umbral_cli::dispatch(app).await
}Then:
cargo run -- migrate
cargo run -- serve
cargo run -- makemigrationsThe subcommands run against the published ambient state (pool, model registry) that the builder set up, so they see every model and plugin the user wired into the builder.
Note build_deferred(), not build(). It wires everything but leaves each
plugin’s on_ready hook unfired, so dispatch can fire it once it knows
what argv asked for — never for migrate, which exists precisely because the
tables those hooks want to seed do not exist yet (gaps3 #41).
Modules§
- scaffold
- Project + plugin scaffolding.
Constants§
- STANDALONE_
COMMANDS - The built-in commands that need NO project — no
App, database, settings, or compiled models — and can therefore run standalone. Every OTHER command (serve,migrate,makemigrations,seed_data, …) needs the project’s compiledApp, so the globalumbralbinary forwards it tocargo run -- <cmd>instead.
Functions§
- builtin_
command_ names - The framework binary’s own subcommands —
serve,migrate,makemigrations, … — read off the derived clap parser rather than hand-listed, so a new subcommand reserves its own name with nothing to remember. - cargo_
run_ forward_ args - Build the
cargoargv for forwarding aumbral <cmd> [args...]invocation to the current project’s binary (cargo run -- <cmd> [args...]). - dispatch
- Parse argv and run the requested management subcommand against the
passed-in App. The user binary’s
main.rscalls this after wiring its App — see the module-level docs for the pattern. - dispatch_
with_ argv - Same as
dispatchbut argv is passed explicitly instead of read from the process. Lets tests exercise the routing without spawning a subprocess. User code should calldispatch(which readsstd::env::args_os()and delegates here). - in_
cargo_ project - Whether
start(or any ancestor) contains aCargo.toml— i.e. we’re inside a Cargo projectcargo runcould build. Mirrors howcargoitself finds the manifest by walking up from the working directory, soumbral <cmd>works from a subdirectory just likecargo rundoes. - try_
run_ standalone - If
argvnames a project-independent built-in, run it and returnSome(result). ReturnNoneotherwise, so the caller (the globalumbralbinary) forwards the command to the project viacargo run.