Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add [cd(DIR)] attribute #2082

Closed
casey opened this issue May 25, 2024 · 6 comments · Fixed by #2438
Closed

Add [cd(DIR)] attribute #2082

casey opened this issue May 25, 2024 · 6 comments · Fixed by #2438

Comments

@casey
Copy link
Owner

casey commented May 25, 2024

Allow setting the working directory of a recipe to an arbitrary directory. Good first issue!

@pedrofgodinho
Copy link

pedrofgodinho commented Jul 6, 2024

Pointing out a usecase for this: it'd facilitate cross-platform support. The project I'm working on currently will likely be developed on both windows and linux. set windows-shell := ['powershell.exe'] is a good first step, but I couldn't find a better way to support both shells other than this hack:

_cd_and_run dir *cmd:
    just _cd_and_run-{{os()}} {{dir}} {{cmd}}

_cd_and_run-linux dir *cmd:
    cd {{dir}} && {{cmd}}

_cd_and_run-macos dir *cmd:
    cd {{dir}} && {{cmd}}

_cd_and_run-windows dir *cmd:
    cd {{dir}}; {{cmd}}

Even this is fairly imperfect, as it doesn't easily allow you to do things like adding a - for ignoring errors (e.g. for a lint recipe to lint 2 subdirectories, when the linter gives exit code 1 when issues are found), among other similar problems.

And adding things like just _cd_and_run frontend npm run build instead of just npm run build here and there isn't the prettiest solution...
An ideal solution would probably be:

[cd(/frontend)]
build:
  npm run build

@artm
Copy link

artm commented Aug 25, 2024

I started working on this together with #2291. It works in simple cases: absolute path or relative path from current directory. I wonder though, where relative paths should actually be reconed from? Is there some precedent in just already which this feature should follow? What about modules?

@casey
Copy link
Owner Author

casey commented Aug 25, 2024

I think that relative paths should always be used relative to whatever would have been the working directory otherwise.

@artm
Copy link

artm commented Aug 26, 2024

Ok, I think that gives me enough direction, thanks.

@NoelJacob
Copy link

NoelJacob commented Sep 21, 2024

i think set working-directory globally and [cd(subdirectory/nested)] per command base would be good idea

@bcheidemann
Copy link
Contributor

I've raised a PR to implement this. However, I've implemented it as [working-directory(DIR)] instead of [cd(DIR)] since this is consistent with the working-directory setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants