Importing & overriding
When your .ahoy.yml gets long, you can move groups of commands into other files with imports.
Importing a file
Section titled “Importing a file”Give a command imports instead of cmd, and the commands in those files become its subcommands:
ahoyapi: v2
commands: db: usage: Database commands imports: - ./.ahoy/db.ahoy.ymlahoyapi: 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 < $1Now you have ahoy db backup and ahoy db restore.
Every imported file needs its own ahoyapi: v2 line.
Optional imports v2.2.0+
Section titled “Optional imports ”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.ymlIf local.ahoy.yml doesn’t exist, ahoy local just doesn’t appear in the list.
Overriding commands
Section titled “Overriding commands”When two commands have the same name, the last one defined wins:
ahoyapi: v2
commands: test: usage: Run tests cmd: npm testahoyapi: v2
commands: shared: imports: - ./.ahoy/base.ahoy.yml
test: usage: Run tests with coverage cmd: npm test -- --coverageHere the test in .ahoy.yml replaces the imported one.
A typical layout
Section titled “A typical layout”Larger projects often keep one file per topic:
project/├── .ahoy.yml└── .ahoy/ ├── db.ahoy.yml ├── docker.ahoy.yml └── deploy.ahoy.ymlahoyapi: 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.ymlSharing commands between projects
Section titled “Sharing commands between projects”Import paths can point outside the project, so several projects can share one set of commands:
commands: shared: imports: - ../../shared-ahoy/docker.ahoy.yml