Skip to content

Add dir: option for per-command working directory #160

@ocean

Description

@ocean

Summary

Add support for a dir: option in command definitions to allow individual commands to run from a specific working directory, rather than always running from the directory containing the .ahoy.yml file.

This would of course be a backwards compatibility breaking feature, so would have to be part of the schema updates for Ahoy v3.

Current Behavior

Currently, all Ahoy commands execute from the directory containing the .ahoy.yml file (AhoyConf.srcDir). This is hardcoded in the command execution logic:

command := exec.Command(cmdItems[0], cmdItems[1:]...)
command.Dir = AhoyConf.srcDir  // Always uses .ahoy.yml directory

To change directories, users must handle it within the command script:

commands:
  example:
    cmd: |
      cd /some/other/directory
      echo "Now in $(pwd)"

Proposed Feature

Add an optional dir: field to command definitions that specifies the working directory for that command:

ahoyapi: v2
commands:
  frontend-build:
    usage: Build frontend assets
    dir: ./frontend
    cmd: npm run build
    
  backend-test:
    usage: Run backend tests  
    dir: ./api
    cmd: composer test
    
  root-command:
    usage: Command that runs from project root
    # No dir specified - uses default (.ahoy.yml directory)
    cmd: echo "Running from $(pwd)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementv3Features or updates that target the next major version.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions