Importing & Overriding
As your command set grows, you can split it across multiple YAML files using imports.
Basic imports
Section titled “Basic imports”A command with imports instead of cmd becomes a namespace for subcommands loaded from other files:
ahoyapi: v2
commands: db: usage: Database commands imports: - ./.ahoy/db.ahoy.ymlahoyapi: v2
commands: backup: usage: Backup 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 < $1This gives you ahoy db backup and ahoy db restore.
Optional imports v2.2.0+
Section titled “Optional imports ”Mark an import as optional: true to silently skip the whole command if none of its files can be found. Useful for local or team-specific command sets 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 simply won’t appear in the listing. Without optional: true, a missing import file is a fatal error.
Overriding commands
Section titled “Overriding commands”Ahoy uses a “last in wins” rule. When the same command name appears in multiple imported files, the last definition 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 -- --coverageThe top-level test command overrides the imported one.
Typical structure
Section titled “Typical structure”A common pattern for larger projects:
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 across projects
Section titled “Sharing commands across projects”Import paths can traverse outside the project directory, which makes it possible to maintain shared command libraries:
commands: shared: imports: - ../../shared-ahoy/docker.ahoy.ymlEach imported file must also declare ahoyapi: v2.