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] Usage of variables and functions in defining global variables #1890

Closed
FeryET opened this issue Feb 10, 2024 · 3 comments
Closed

Comments

@FeryET
Copy link

FeryET commented Feb 10, 2024

Hi.

Right now if I want define a variable that can be declared easily via interpolation with other variables, I have to use 'executable line' format like this:

ABS_BASE_DIR := `echo "$(pwd)/some_dir"`

While IMO this could be way more readable and consistent:

ABS_BASE_DIR := '{{ justfile_directory() }}/some_dir'

We currently cannot interpolate global variables using other variables or pre-built functions in the recipe.

@casey
Copy link
Owner

casey commented Feb 10, 2024

Does this work? You can use the / operator like so:

foo := justfile_directory() / 'some_dir'
$ just --evaluate foo
foo := "/Users/bar/some_dir"

@FeryET
Copy link
Author

FeryET commented Feb 10, 2024

Does this work? You can use the / operator like so:

foo := justfile_directory() / 'some_dir'
$ just --evaluate foo
foo := "/Users/bar/some_dir"

Yes, it works and it's awesome! Needs to be explicitly documented, tho.

Still in some cases variable interpolation is far easier to read and understand as it reminds people of go template engine or jinja. e.g.:

registry_url := 'example.registry.local'

image_name := 'python'

image_tag  := '3.8-slim'

full_image_id := '{{ registry_url }}/{{  image_name }}:{{  image_tag }}'

@build:
         docker build . -t {{ full_image_id }}

@push:
         docker push {{ full_image_id }}

@casey
Copy link
Owner

casey commented Feb 11, 2024

This is documented here. Interpolation is definitely wanted, see #11.

@casey casey closed this as completed Feb 11, 2024
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

No branches or pull requests

2 participants