CLI commands
The cardinal commands an app builder uses, and how an app adds its own cardinal app:command.
Commands for app work
| Command | Does |
|---|---|
cardinal app new NAME [--with-frontend] [--requires APP]... | Writes apps/NAME, runs git init, adds it to cardinal.workspace.exs |
cardinal app get SOURCE [--ref REF] [--link PATH] [--trust] [--resolve-deps] [--overwrite] [--skip-build] | Fetches an app and pins it. See Publishing |
cardinal app install -t HOST APP... | Installs apps and any missing requirements on a site |
cardinal app uninstall -t HOST APP | Uninstalls. Tables are renamed, not dropped |
cardinal app remove APP [--no-backup] [--force] | Takes the app out of the workspace |
cardinal app list | Apps in this build with versions, in hook order |
cardinal app check | Requirements, versions, cycles, mix.exs deps, and rows that widen another app's roles |
cardinal app build [APP]... | Builds desk plugins and app frontends |
cardinal meta check | Compiles every RecType, permission file and website file |
cardinal test --app APP | Runs the app's ExUnit tests against throwaway sites |
cardinal i18n extract|new|update --app APP | Translation catalogs. See Translations |
cardinal migrate -t HOST|all | Runs migrations, patches and fixture syncs for installed apps |
cardinal build | Builds the desk and every app's plugins, and writes build/build.json |
cardinal perm explain -t HOST --user U --rectype R [--name N] --ptype P | Prints each step of a permission decision |
cardinal jobs list|retry|cancel|trigger -t HOST | Inspect and run background jobs |
cardinal schema orphans -t HOST | Columns a RecType no longer has. Migrations never drop them |
app new turns - and spaces in NAME into _.
What app new writes
| File | Holds |
|---|---|
app.exs | The manifest, with requires: [cardinal: "~> <major>.<minor>"] |
mix.exs | Depends on cardinal_core, cardinal_jobs and each --requires app |
lib/<name>.ex | The use Cardinal.App module |
rectypes/README.md | An empty RecType folder |
test/test_helper.exs, test/<name>_test.exs | A first test on a throwaway site |
as_system_allowlist.txt | The empty allow-list |
.github/workflows/ci.yml | Format check and cardinal test --app |
LICENSE, README.md, .formatter.exs, .gitignore | Repository files |
frontend/ | With --with-frontend: package.json, vite.config.ts, src/index.ts, src/index.test.ts |
Add a command to cardinal
An app lists its commands under cli. Seed adds three:
cli: [{"run", Seed.CLI.Run}, {"status", Seed.CLI.Status}, {"resume", Seed.CLI.Resume}]They run as cardinal seed:run, cardinal seed:status and cardinal seed:resume. App commands always carry the colon, so they cannot shadow a platform command.
A command implements Cardinal.CLI.Command with run(args), where args are the words after the command name. It returns :ok, or {:error, message}, which the CLI prints before exiting with code 1.
defmodule Seed.CLI.Run do
@behaviour Cardinal.CLI.Command
@usage "Usage: cardinal seed:run -t HOST --domains erp,gst,hrms -n N --from DATE"
@impl true
def run(args) do
case OptionParser.parse(args, strict: [tenant: :string, domains: :string, n: :integer, from: :string],
aliases: [t: :tenant]) do
{opts, [], []} -> if opts[:tenant], do: start(Map.new(opts)), else: {:error, @usage}
_ -> {:error, @usage}
end
end
endThe CLI starts the database and the application before run/1. A command that works on one site takes -t HOST itself and opens its own transaction with Cardinal.DB.transaction/2.