Command execution
Finding your config
Section titled “Finding your config”When you run a command, Ahoy:
- Uses the file given with
--file(or-f), if there is one - Otherwise looks for
.ahoy.ymlin the current directory, then in each parent directory - Changes to the directory that file is in
- Runs your command from there
This means you can run ahoy from any subdirectory in your project and it always behaves consistently.
Arguments
Section titled “Arguments”Arguments are passed to commands as bash positional parameters:
commands: greet: cmd: echo "Hello, $1!"
copy: cmd: cp $1 $2
run-in-container: cmd: docker-compose exec app "$@"ahoy greet World # Hello, World!ahoy copy src.txt dest.txtahoy run-in-container npm test$@ passes all arguments through, which is handy for wrapper commands. Use $# to check the argument count, and $0 for the command name.
Everything after the command name reaches your command unchanged, flags included, so wrapping a tool with its own options just works:
commands: phpunit: cmd: docker compose exec app vendor/bin/phpunit "$@"ahoy phpunit --filter=MyTest --stop-on-failureAhoy’s own flags, such as --verbose and --file, only count when they come before the command name, so they can’t clash with your command’s options.
Ahoy removes a -- only when it comes straight after the command name. Any other -- is passed to your command, which matters for tools that use their own separator:
ahoy k exec mypod -- ls /app # kubectl gets its --ahoy run npm test -- --watch # npm passes --watch to the test scriptInteractive commands
Section titled “Interactive commands”Commands use the same stdin, stdout and stderr as the terminal or script that ran Ahoy. Ahoy doesn’t read, buffer or copy them, so a command behaves exactly as if you’d typed it yourself:
commands: shell: usage: Open a shell in the app container cmd: docker-compose exec app bash
mysql: usage: Open a MySQL shell cmd: mysql -u$DB_USER -p$DB_PASS $DB_NAMEFrom a terminal you get a real prompt, line editing and working pipes. From a script or CI job, the command sees the same pipes or files it would see without Ahoy.
Full-screen tools and TUI commands
Section titled “Full-screen tools and TUI commands”Full-screen and menu tools need to ask the terminal how big it is. Because Ahoy hands over the real terminal, they get the right answer and draw properly:
commands: pick-env: usage: Choose an environment to deploy to cmd: gum choose staging production
logs: usage: Browse container logs interactively cmd: docker compose logs --tail=1000 | fzf --tacThis covers tools built on Bubble Tea such as gum and glow, which draw on stderr, along with progress bars and spinners.
Ahoy doesn’t buffer output either - a long-running command’s output appears as the command writes it, not in a burst when Ahoy exits. Some programs buffer their own output when it goes to a pipe or file, and Ahoy can’t change that.
Chaining commands
Section titled “Chaining commands”You can call other Ahoy commands from within a command:
commands: ci: usage: Run the full CI pipeline locally cmd: | ahoy install ahoy lint ahoy test
install: cmd: npm install
lint: cmd: npm run lint
test: cmd: npm testCustom entrypoints
Section titled “Custom entrypoints”By default Ahoy runs each command with bash -c '{{cmd}}'. Set entrypoint at the top of the file to use a different interpreter:
ahoyapi: v2
entrypoint: - node - "-e" - "{{cmd}}"
commands: hello: cmd: console.log("Hello from Node.js!")ahoyapi: v2
entrypoint: - python3 - "-c" - "{{cmd}}"
commands: hello: cmd: print("Hello from Python!")The entrypoint can use these placeholders:
{{cmd}}: the command body{{name}}: the command name (also available as$0)
Exit codes
Section titled “Exit codes”Ahoy exits with 0 when your command succeeds and 1 when it fails, whatever code the command returned. That’s enough to chain commands in the shell:
ahoy test && ahoy deployInside a command, the usual bash operators decide what runs next:
&&runs the next command only if the previous one succeeded||runs the next command only if the previous one failed;always runs the next command
commands: only-run-1-2-and-4: cmd: | echo "1 - If this passes" && echo "2 - Then do this" || echo "3 - Or do this if 1 or 2 fails" ; echo "4 - Do this no matter what"Troubleshooting
Section titled “Troubleshooting”- Run with
--verbose(before the command name) to see the exact command Ahoy ran. - Commands run in a subshell. They get a copy of your environment, but can’t change your current directory or set variables in your shell.
- Quotes can get lost when one command passes arguments to another. Check
--verbosefirst, then try swapping single and double quotes. Usingcmd: |for anything complicated keeps YAML quoting out of the way. - If Ahoy can’t read your file, run
ahoy config validate. It reports YAML mistakes and fields Ahoy doesn’t support.