Repository navigation
03 Recipes and Scripts
croft gives you two ways to define a command. Use whichever shape matches the command's complexity — they coexist, neither shadows the other, and resolution is deterministic.
Declarative TOML in croft.toml. Best for one-liners and small
sequences.
[command.up]
desc = "Start all services"
run = "docker compose up -d"
[command.test]
desc = "Run test suite"
needs = ["up"]
in = "app"
run = "composer test"
forward_args = trueneeds runs the listed recipes first; non-zero exit halts the chain.
run is either a single string (one shell-parsed command) or an
array of step references. Inside an array, a step is either an inline
shell line or another recipe name — recipe-name steps re-enter the
runtime so needs and in apply transitively.
[command.check]
run = ["check:format", "check:lint", "test"]
[command.check.parallel]
parallel = true # array steps run concurrentlyin = "<service>" execs the command inside a Docker Compose service
after a status preflight. Absent → host. tty = true allocates a
TTY (required for shells, irrelevant for pure-stdout commands).
forward_args = true appends the trailing CLI args to the command:
croft test --filter Login → composer test --filter Login.
Named override layers, activated by --profile <name>:
[command.test]
run = "composer test"
tty = true
[command.test.profile.ci]
tty = false
forward_args = true
env = { XDEBUG_MODE = "off" }croft --profile ci test --testdox runs composer test --testdox
with tty = false and the override env.
Plain shell files — anything that grows past one or two lines.
# .croft/commands/seed
#!/usr/bin/env bash
# @desc: Seed the database with development data
# @in: app
# @env: APP_ENV=local
set -euo pipefail
php artisan migrate:fresh
php artisan db:seedcroft scans .croft/commands/ at load time. The optional # @key: value frontmatter (terminated by the first non-# @ line) sets the
same fields you'd put in a [command.*] recipe:
| Key | Equivalent recipe field |
|---|---|
@desc |
desc |
@in (alias @service) |
in |
@tty |
tty |
@needs |
needs (comma-separated) |
@env |
env (comma-separated K=V pairs) |
@forward-args (alias @forward_args) |
forward_args |
Hidden files (.foo) and files starting with _ are skipped. Names
collide with [command.*] keys at config-load time and error
explicitly.
Every .croft/commands/<name> script runs with two extra env vars
set by croft, on top of the resolved Environments
layers:
| Var | Value |
|---|---|
CROFT_PROJECT_DIR |
Host path to the worktree project root. |
CROFT_SCRIPT_DIR |
Host path to the script file's parent directory. |
Both are host-side paths even when the script runs inside a
service (@in:) or devcontainer — convenient on the host,
meaningless inside a container unless that path is bind-mounted.
Script-author @env: (or the env = {...} table) overrides win,
so shadowing either is intentional.
Use them instead of dirname "$0" boilerplate, e.g. to source a
sibling helper:
#!/usr/bin/env bash
set -euo pipefail
source "$CROFT_SCRIPT_DIR/_lib.sh"Recipes ([command.<name>]) don't receive these vars — they're a
scripts-only contract.
- Recipe: 1–3 commands, no flow control, happy in a TOML cell.
-
Script: anything with conditionals, loops, set-euo-pipefail,
multiple
ifbranches, or that benefits from a real shebang line (e.g.#!/usr/bin/env -S deno run -A).
Don't mix the two for the same command — recipe-vs-script is a name collision.
When you run croft <name> [args...] (no explicit subcommand), the
resolver tries:
- Built-in subcommand (e.g.
list,doctor). -
[command.<name>]recipe. -
.croft/commands/<name>script. -
<name>as a docker-compose subcommand (passthrough), if[runtime].compose_passthrough = true. -
<name>as a compose service name (exec into it), if[runtime].service_passthrough = true.
croft which <name> prints which slot resolved.
- Configuration Reference for the recipe schema in full.
- Commands Reference for the built-in subcommands you can't override.
-
Environments for how recipe
envinteracts with.envfiles and[env]arithmetic.
croft is dual-licensed under MIT or Apache 2.0. Source: github.com/nsrosenqvist/croft. Back to Home.