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

[Feature Request] An option to disable change directory for all recipes in justfile #2291

Open
piotrekkr opened this issue Aug 2, 2024 · 3 comments

Comments

@piotrekkr
Copy link

Hello. just is a great tool and I really like it. However this automatic change directory behavior and using [no-cd] in all my recipes is a bit annoying (but still acceptable).
Would you consider adding some setting to disable this behaviour? Something like set no-cd and new attribute [do-cd] or something like this?

My use case.

All projects I'm working on are in ~/Projects.

~/Projects/my-project-1
~/Projects/my-project-2
...

I want to reuse one justfile located in ~/Projects/justfile. All those projects contain terraform configuration that I'm working on. When I want to change infrastructure of some project I will:

  1. Go into ~/Projects/my-project-2
  2. Make changes in infra config
  3. Run validate, fmt, plan
  4. If all is okay then apply infrastructure

There are some other common actions I do on all projects also but this is not important.

To work with terraform I need to be inside the directory that contains configuration. To make it work with just each recipe needs to have this [no-cd] added.

My working justfile looks like similar to this:

set quiet := true

[private]
[positional-arguments]
run-tf *args='':
    # this is actually more complicated command using docker with volumes and whatnot
    # but for this example I simplified it
    terraform "$@"

[no-cd]
init:
    just run-tf init

[no-cd]
upgrade:
    just run-tf init -upgrade

[no-cd]
validate:
    just run-tf validate

[no-cd]
plan:
    just run-tf plan

[no-cd]
apply:
    just run-tf apply

[no-cd]
destroy:
    just run-tf destroy

[no-cd]
cli:
    just run-tf bash

[no-cd]
format:
    just run-tf fmt -recursive .

[no-cd]
output *args='':
    just run-tf output "$@"

alias console := cli

All is working fine but would be great if I could just use something like set no-cd and remove all those [no-cd] lines. If I wanted to change dir to jsutfile dir I could then add [do-cd] in recipe and it would work the standard way.

Would you consider adding setting like this?

Thanks

@casey
Copy link
Owner

casey commented Aug 2, 2024

I think set no-cd would be reasonable. The working directory logic has been recently refactored into a single function, ExecutionContext::working_directory, which has access to settings, so it should actually be a pretty simple PR.

@artm
Copy link

artm commented Aug 25, 2024

I have started tackling this. I think it can be combined with #2082, to avoid multiplying attributes beyond necessity:

  • set no-cd makes that by default working directory isn't modified
  • [cd(DIR)] sets alternative working directory for a recipe with or without global no-cd setting
  • [cd] undoes global set no-cd for a marked recipe (instead of the suggested [do-cd]
  • setting [cd] and [no-cd] on the same recipe should cause an error on startup saying they are incompatible.

@casey
Copy link
Owner

casey commented Aug 25, 2024

@artm That all seems reasonable to me!

artm added a commit to artm/just that referenced this issue Aug 25, 2024
artm added a commit to artm/just that referenced this issue Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants