Zero CLI
The zero framework ships a small CLI for project tasks like scaffolding migrations. Build it from your app (or a framework checkout) with:
bash
zig build zero --prefix=/usr/local/bin
or
zig build zero
sudo cp zig-out/bin/zero /usr/local/binThis puts a zero binary in zig-out/bin. Run it with no arguments or --help to print usage and exit.
Commands
migrator add
Scaffolds a new migration in src/migrations/ and (re)generates the registry in src/migrations/all.zig:
bash
zero migrator add --name create-users
# also accepts the = form:
zero migrator add --name=create-userszerosanitizes--name(hyphens →_). It sets the generated file name and the migration number (Unix epoch seconds).- Re-adding an existing name is a safe no-op.
zeroignoresMigrationAlreadyExists. - See Migrations for the full workflow: editing the generated
<name>_runfunction, callingmigrations.all(app), thenapp.runMigrations().
--help / -h
Print the CLI usage and exit.
Errors
| Condition | Result |
|---|---|
--name with no value | error: --name requires a value (MissingNameValue) |
migrator without add | prints help and exits |
| unknown subcommand / flag | error: unknown command ... / error: unknown flag ... (UnknownFlag) |
migrator add without --name | error: migrator add requires --name <name> (MissingName) |
Building CLI applications (not the zero tool)
To run your own app as a command instead of an HTTP server, use the app-level CLI API in CLI Apps:
App.newCmd(allocator, io, em)— likeApp.newbut does not start the HTTP or metrics servers.app.SubCommand(name, handler, opts)— register a subcommand (handler: fn(*Context) anyerror!void).app.runCmd(args)— parse argv, dispatch to a subcommand, and build a CLIContext.ctx.Param("name")— read a--flag value/--flag=value/-f valueargument.
Related
- Migrations — the
migrator addworkflow end to end. - CLI Apps — running your app as a CLI / one-shot job.
- Benchmark — the
zig build benchharness (a separate binary).