Writing commands
An Ahoy command is a shell command with a name and some help text, written in YAML.
A minimal command
Section titled “A minimal command”A command needs a name and a cmd. Everything else is optional, but a usage line is worth adding:
ahoyapi: v2
commands: hello: usage: Say hello to someone cmd: echo "Hello, $1!"The usage line is what people see when they run ahoy, so keep it short and clear.
Arguments
Section titled “Arguments”Arguments arrive as normal bash positional parameters:
commands: shell: usage: Open a shell in a container cmd: docker compose exec $1 bash
copy: usage: Copy a file between containers cmd: docker compose cp $1 $2
run: usage: Run any command in the app container cmd: docker compose exec app "$@"$1, $2 for specific positions; $@ to forward everything. The last pattern is great for transparent wrappers:
ahoy run npm test -- --watchFlags count as arguments. Everything you type after the command name reaches your command as typed, in the same order:
ahoy run npm test --watchahoy run chown -R www-data:www-data .Command execution has the details, including how -- is handled.
Multi-line scripts
Section titled “Multi-line scripts”For anything longer than one line, use a YAML block (|). It’s normal bash inside:
commands: setup: usage: Set up the project from scratch cmd: | echo "Installing dependencies..." npm install
echo "Running migrations..." ./migrate.sh
echo "All done. Run 'ahoy start' to begin."Longer help text v3
Section titled “Longer help text ”usage is the one line shown in the list. description is longer help, shown when someone runs ahoy help <command>:
commands: deploy: usage: Deploy the application description: | Deploys to the given environment, running tests and building assets first. Needs .env.deploy to be set up.
Usage: ahoy deploy staging ahoy deploy production
The production deploy asks for confirmation unless CI=true is set. cmd: ./scripts/deploy.sh $1Aliases v2.2.0+
Section titled “Aliases ”Aliases are short names for a command. They’re listed next to the main name:
commands: start-dev: usage: Start the development environment aliases: ["up", "start"] cmd: docker compose up -d
open-shell: usage: Open a shell in the app container aliases: ["shell", "sh", "bash"] cmd: docker compose exec app bashGive the command a descriptive name, and add short aliases for the ones you type all day.
Calling other commands
Section titled “Calling other commands”A command can run other Ahoy commands:
commands: ci: usage: Run the full CI pipeline locally cmd: | ahoy lint ahoy test ahoy build
fresh: usage: Tear down and rebuild everything cmd: | ahoy down docker compose build --no-cache ahoy up ahoy installAsking before destructive commands
Section titled “Asking before destructive commands”For commands that can’t be undone, add a confirm helper that asks first. This one also works in scripts and CI, where you answer in advance with AHOY_CONFIRM_RESPONSE=y:
commands: db:reset: usage: Reset the database to a clean state cmd: | ahoy confirm "This will destroy all database data. Continue?" || exit 0 docker compose exec db mysql -u"$DB_USER" -p"$DB_PASS" -e \ "DROP DATABASE IF EXISTS \`$DB_NAME\`; CREATE DATABASE \`$DB_NAME\`;" echo "Database reset."
confirm: hide: true cmd: | if [ -z "${AHOY_CONFIRM_RESPONSE}" ]; then read -r -p ">> $1 [y/N] " response else response="${AHOY_CONFIRM_RESPONSE}" echo ">> $1 [y/N] ${response}" fi response=$(printf '%s' "$response" | tr '[:upper:]' '[:lower:]') if [ "$response" != "y" ] && [ "$response" != "yes" ]; then echo "Cancelled." exit 1 fi # Answered in advance, so pause for a chance to press Ctrl+C. if [ -n "${AHOY_CONFIRM_RESPONSE}" ] && [ "${AHOY_CONFIRM_WAIT_SKIP}" != "1" ]; then sleep 3 fihide: true keeps a helper out of the command list. You can still run it.
Wrapping other tools
Section titled “Wrapping other tools”Ahoy works well for wrapping long container commands:
commands: drush: usage: Run Drush in the CLI container cmd: docker compose exec cli drush --root=/var/www/html/web "$@"
composer: usage: Run Composer in the CLI container cmd: docker compose exec cli composer "$@"
node: usage: Run Node.js commands in the app container cmd: docker compose exec app node "$@"Now the team can run ahoy drush cache:rebuild or ahoy composer require vendor/package. The wrapped tool gets all its own flags, even ones Ahoy also uses:
ahoy drush --help # Drush's helpahoy composer require --dev vendor/pkgahoy drush sql:query --extra=-A "SELECT 1"ahoy node --versionBecause --help goes to the wrapped tool, use ahoy help drush to see Ahoy’s help for the command.
Commands with their own env file v2.3.0+
Section titled “Commands with their own env file ”Use env to load settings for one command:
commands: deploy: usage: Deploy to staging env: .env.deploy cmd: | echo "Deploying to $DEPLOY_HOST..." rsync -avz ./dist/ $DEPLOY_HOST:$DEPLOY_PATHThe Environment variables guide covers env files in full.
Example files
Section titled “Example files”The repository has example files you can copy:
- examples.ahoy.yml: around 30 commands for Docker, databases, testing, Drupal and deployment.
ahoy config initdownloads it, and it uses nearly every Ahoy feature, so it’s a good file to read. - docker.ahoy.yml: Docker Compose commands to import into your own config.
- confirmation.ahoy.yml: the confirmation helper on its own, ready to import.
Every field is listed in the YAML schema.