CLI Commands
ulo new, ulo generate and ulo dev, with every option and the files each writes.
ulo new
ulo new <name> [--transport <transport>] [--db <module>-<backend>]Writes a project into a new directory named <name>. The name is letters, digits, - and _, starts with a letter, and is not a Rust keyword or the name of a crate the project depends on. The command refuses an existing directory and removes what it wrote if a write fails.
ulo new my-app
cd my-app
cargo test
cargo runcurl http://127.0.0.1:3000/greetings/Ada
# {"message":"Hello, Ada!"}The files are described on Project Structure. The project's ulo-* dependencies are pinned to the CLI's exact version, as ulo = "=0.1.0-alpha.3", which resolves from crates.io.
Transports
--transport defaults to http.
| Transport | Serves | Health |
|---|---|---|
http | HTTP/1.1 and HTTP/2 on hyper | /health/live, /health/ready, /health/started |
ws | A WebSocket gateway on the HTTP server's port | The same HTTP probes |
grpc | gRPC from proto/greeter.proto | grpc.health.v1 |
rpc-tcp, rpc-udp | RPC over TCP or UDP | None |
rpc-nats, rpc-redis, rpc-rabbitmq, rpc-mqtt, rpc-kafka | RPC over a broker | None |
rpc-kafka builds librdkafka and needs a C toolchain. A broker transport connects to the broker named in config/app.toml when the project starts. Default addresses written to config/app.toml:
| Transport | Key | Value |
|---|---|---|
http, ws | server.address | 127.0.0.1:3000 |
grpc | server.address | 127.0.0.1:50051 |
rpc-tcp | server.address | 127.0.0.1:7000 |
rpc-udp | server.address | 127.0.0.1:7001 |
rpc-nats | server.url | nats://127.0.0.1:4222 |
rpc-redis | server.url | redis://127.0.0.1:6379 |
rpc-rabbitmq | server.url | amqp://guest:guest@127.0.0.1:5672/%2f |
rpc-mqtt | server.url | mqtt://127.0.0.1:1883 |
rpc-kafka | server.brokers | 127.0.0.1:9092 |
Environment variables named APP_<SECTION>__<KEY> override the file: APP_SERVER__ADDRESS overrides server.address.
Databases
--db adds a database layer: the store module imported in src/app.rs, a [database] section in config/app.toml, and src/database.rs, a service that injects the client.
--db | Client | Rust |
|---|---|---|
sqlx-postgres, sqlx-mysql, sqlx-sqlite | sqlx::PgPool, MySqlPool, SqlitePool | 1.94 |
seaorm-postgres, seaorm-mysql, seaorm-sqlite | sea_orm::DatabaseConnection | 1.94 |
diesel-postgres, diesel-mysql, diesel-sqlite | A deadpool Pool of diesel-async connections | 1.89 |
mongodb | mongodb::Client | 1.88 |
redis | redis::aio::ConnectionManager | 1.88 |
The generated manifest states the Rust version the combination needs. Migrations are not generated; each store module takes them through .migrate(..). See Database.
ulo generate
ulo generate <module|provider|controller|gateway|resolver> <name> [--transport <http|rpc>]Run it from the project root. It writes one new file under src/ and prints the lines that register it. It edits no existing source, since rewriting a file loses its formatting and comments. It refuses to overwrite a file and refuses a name that is not a Rust identifier. --transport applies to controller alone.
| Kind | File | Item |
|---|---|---|
module | src/<name>_module.rs | <Name>Module |
provider | src/<name>.rs | <Name> |
controller | src/<name>_controller.rs | <Name>Controller; --transport rpc for RPC handlers, HTTP otherwise |
gateway | src/<name>_gateway.rs | <Name>Gateway |
resolver | src/<name>_resolver.rs | <Name>Resolver, an async-graphql root object |
ulo generate controller user_profileCreated src/user_profile_controller.rs
Declare it where the project's modules are, usually src/main.rs:
mod user_profile_controller;
Register it in the module that serves it:
m.controller::<crate::user_profile_controller::UserProfileController>();
It needs these in Cargo.toml:
ulo-http = "=0.1.0-alpha.3"The generated controller serves GET /user-profile:
use serde::Serialize;
use ulo::{controller, handlers};
use ulo_http::Json;
#[derive(Debug, Serialize)]
pub struct UserProfileListing {
pub items: Vec<String>,
}
#[controller]
pub struct UserProfileController;
#[handlers]
impl UserProfileController {
#[ulo_http::get("/user-profile")]
fn list(&self) -> Json<UserProfileListing> {
Json(UserProfileListing { items: Vec::new() })
}
}Registration lines per kind:
| Kind | Printed registration |
|---|---|
module | m.import(crate::<name>_module::<Name>Module); |
provider | m.provide::<crate::<name>::<Name>>(); |
controller | m.controller::<crate::<name>_controller::<Name>Controller>(); |
gateway | The same for <Name>Gateway, and m.import(ulo_ws::WsModule::for_root()); once per application |
resolver | A comment: add the resolver to the query root's #[derive(MergedObject)] |
A kind that needs a crate the project may not have prints its Cargo.toml line: ulo-http or ulo-rpc for a controller, ulo-ws for a gateway, async-graphql = "7" for a resolver. Each generated file carries a test.
ulo dev
ulo dev [options] [-- <application arguments>]Runs the project and restarts it when a .rs or .toml file changes. It must be run from a directory with a Cargo.toml. It builds with cargo build and starts the binary the build reports. Cargo's selection flags apply to the build and everything after -- goes to the application. Behaviour while a rebuild runs, and a failed build, is on Development Workflow.
Options:
| Option | Meaning |
|---|---|
--release | Build and run in release mode |
-p, --package <SPEC> | Package to run, for a workspace with more than one |
--bin <NAME> | Run this binary instead of the package default |
--example <NAME> | Run this example instead of a binary; refused with --bin |
-F, --features <FEATURES> | Features to activate; repeat the flag or comma-separate the list |
--all-features | Activate every feature of every selected package |
--no-default-features | Do not activate the default feature |
--cargo-arg <ARG> | Forward one argument to cargo as given; repeat it once per argument |
--listen <ADDR> | Hold a listening TCP socket on ADDR across restarts. Unix only |
ulo dev --release -p my-app
ulo dev -p my-app --example demo -F tls -- --config config/local.toml
ulo dev --cargo-arg --offline --cargo-arg --timingsTarget and feature selectors go before the --. The cargo command is assembled in a fixed order: build, --release, the --package, --bin and --example selectors, --features, --all-features, --no-default-features, then the --cargo-arg values in the order given.
--listen
--listen ADDR binds ADDR once and passes the socket to every child as file descriptor 3 with LISTEN_FDS=1, LISTEN_FDNAMES and LISTEN_PID, set through a trampoline (ulo __exec, hidden) so the process ID matches the child's. Every child also runs with ULO_DEV=1, under which a server written with the same address adopts the held socket. Connections arriving while no child accepts queue in the socket's backlog.
ADDRis a socket address with a host:127.0.0.1:3000or0.0.0.0:8080, optionally prefixedtcp://. A bare port and audp://address are refused.- A UDP link is outside
--listenand binds its own address. - On a platform without descriptor passing the flag is ignored with a warning.
The application side is on Socket activation.