cardinal

CLI commands

The cardinal commands an app builder uses, and how an app adds its own cardinal app:command.

Commands for app work

CommandDoes
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 APPUninstalls. Tables are renamed, not dropped
cardinal app remove APP [--no-backup] [--force]Takes the app out of the workspace
cardinal app listApps in this build with versions, in hook order
cardinal app checkRequirements, 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 checkCompiles every RecType, permission file and website file
cardinal test --app APPRuns the app's ExUnit tests against throwaway sites
cardinal i18n extract|new|update --app APPTranslation catalogs. See Translations
cardinal migrate -t HOST|allRuns migrations, patches and fixture syncs for installed apps
cardinal buildBuilds the desk and every app's plugins, and writes build/build.json
cardinal perm explain -t HOST --user U --rectype R [--name N] --ptype PPrints each step of a permission decision
cardinal jobs list|retry|cancel|trigger -t HOSTInspect and run background jobs
cardinal schema orphans -t HOSTColumns a RecType no longer has. Migrations never drop them

app new turns - and spaces in NAME into _.

What app new writes

FileHolds
app.exsThe manifest, with requires: [cardinal: "~> <major>.<minor>"]
mix.exsDepends on cardinal_core, cardinal_jobs and each --requires app
lib/<name>.exThe use Cardinal.App module
rectypes/README.mdAn empty RecType folder
test/test_helper.exs, test/<name>_test.exsA first test on a throwaway site
as_system_allowlist.txtThe empty allow-list
.github/workflows/ci.ymlFormat check and cardinal test --app
LICENSE, README.md, .formatter.exs, .gitignoreRepository 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:

seed/app.exs
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.

seed/lib/cli/run.ex
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
end

The 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.

On this page