Fix the handling of CLI option dir. by trulede · Pull Request #2703 · go-task/task
Values for --dir provided at the CLI are chomped in the call to getRootNode(). This means that the working dir for task is not actually set according to the user intention.
Grounding notes:
USER_WORKING_DIR = Directory task is called from. Fixed (does not change).
TASKFILE_DIR = Directory of the current taskfile (when running a task).
TASK_DIR = The working directory of a task.
- defaults to c.Dir (which shadows e.Dir)
- task.dir modifies -> join(c.Dir, task.Dir)
- cli
--dirmodifies c.Dir (and thus may impact on previous line)
ROOT_DIR = Directory of the root taskfile. Fixed (does not change).
This PR fixes the chomping and ensures that a user (or test) provided --dir is used as the basis for determining a tasks working dir. If a task specifies a task.dir, that will be resolved relative to the provided --dir.
As a result of that change the RootDIr needs to be explicitly set, rather than inferred from c.Dir (which itself is set from e.Dir).
Observation: prior to this PR the dir cli option had no effect.
Note: one test needed modification because it was running in the ROOT_DIR rather than in the provided dir. This seems to have been a mistake in the test.
fixes #2102
Further observation: previous PR's have caused regressions. I do believe this change will be more resiliant.
68d5095