Skip to content

Importing & overriding

When your .ahoy.yml gets long, you can move groups of commands into other files with imports.

Give a command imports instead of cmd, and the commands in those files become its subcommands:

.ahoy.yml
ahoyapi: v2
commands:
db:
usage: Database commands
imports:
- ./.ahoy/db.ahoy.yml
.ahoy/db.ahoy.yml
ahoyapi: v2
commands:
backup:
usage: Back up the database
cmd: mysqldump -u$DB_USER -p$DB_PASS $DB_NAME > backup.sql
restore:
usage: Restore from a backup file
cmd: mysql -u$DB_USER -p$DB_PASS $DB_NAME < $1

Now you have ahoy db backup and ahoy db restore.

Every imported file needs its own ahoyapi: v2 line.

Normally Ahoy stops with an error if it finds no commands across a command’s imported files, for example because none of the files exist. Add optional: true and Ahoy skips the command quietly instead. If some of the files are missing, Ahoy still keeps the commands from the ones it found. This suits personal or team-only commands that not everyone has:

ahoyapi: v2
commands:
local:
usage: Local development extras
optional: true
imports:
- ./local.ahoy.yml

If local.ahoy.yml doesn’t exist, ahoy local just doesn’t appear in the list.

When two commands have the same name, the last one defined wins:

.ahoy/base.ahoy.yml
ahoyapi: v2
commands:
test:
usage: Run tests
cmd: npm test
.ahoy.yml
ahoyapi: v2
commands:
shared:
imports:
- ./.ahoy/base.ahoy.yml
test:
usage: Run tests with coverage
cmd: npm test -- --coverage

Here the test in .ahoy.yml replaces the imported one.

Larger projects often keep one file per topic:

project/
├── .ahoy.yml
└── .ahoy/
├── db.ahoy.yml
├── docker.ahoy.yml
└── deploy.ahoy.yml
.ahoy.yml
ahoyapi: v2
commands:
db:
usage: Database commands
imports:
- ./.ahoy/db.ahoy.yml
docker:
usage: Container commands
imports:
- ./.ahoy/docker.ahoy.yml
deploy:
usage: Deployment commands
imports:
- ./.ahoy/deploy.ahoy.yml

Import paths can point outside the project, so several projects can share one set of commands:

commands:
shared:
imports:
- ../../shared-ahoy/docker.ahoy.yml