-
Notifications
You must be signed in to change notification settings - Fork 500
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
Support defining external justfile locations through env var #1849
Conversation
Thanks for the PR! I actually think that expanding environment variables in paths, e.g.,
What do you think? |
Expanding the variables in the path was one of my suggestions in #1580, so that's fine with me too 🙂 I get your argument for starting with I'll have a look at |
1 │ mod foo '$FOO/mod.just' | ||
│ ^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pointers here would be nicer on the path, but I couldn't figure out how to get to a token from relative
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relative is an Option, but in the case of an error, you know there's a path, so you can unwrap it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's already unwrapped. The difficulty I face is that relative
is a StringLiteral
, and I need a Token
in the error handling to position the pointers. I don't know how to get back from the literal string to the token.
I thought about perhaps using the module token and iterating to the next token after (something like module.token.next
), but I don't see an easy way to do it this way either 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@casey Any remaining ideas on this? Otherwise I keep it as is 🙁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mod
parser uses parse_string_literal
, but there's also parse_string_literal
token which returns both the string literal and the token, if you store the token in mod
in addition to the string literal, you can use it in the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See review comments!
1 │ mod foo '$FOO/mod.just' | ||
│ ^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relative is an Option, but in the case of an error, you know there's a path, so you can unwrap it.
I see some new commits. Is this ready for review? |
I just landed #2055, which adds a a new kind of string literal. Strings prefixed with |
Cool! No worries, I'm just happy the feature works 🙂 |
The shell expansion feature is very handy for managing different sets of variable for different environments, thanks for implementing it! Il might be worth mentioning in the documentation that the expansion supports fallbacks: I was not familiar with the fallback feature and it took me a while (well, a lot of time, until I stumbled on this thread and the 17 Jan post about the merits of Something like:
In case someone is interested here is my strategy to manage multiple envs: foo_default := "FOO_0"
bar_default := "BAR_0"
# The "envs" folder contains one <env-name>.env for each environment with the appropriate variables:
# env-1.env:
# ENV_FOO=FOO1
# ENV_BAR=BAR1
#
# env-2.env:
# ENV_FOO=FOO2
# ENV_BAR=BAR2
#
# If the JUST_ENV variable is not set load the default.env file, if it's missing use the hard coded values above
set dotenv-filename := x'envs/${JUST_ENV:-default}.env'
foo := env_var_or_default('ENV_FOO', foo_default)
bar := env_var_or_default('ENV_BAR', bar_default)
# Use foo and bar variables in the recipes |
@fabiomoratti Nice, I didn't know that |
This extends just so you can define multiple locations from which it tries to import other justfiles. This allows, for example, to put shared justfiles in a user defined global location once, rather than having to manage duplicates in every repo they are used in or deal with symlinks.
Example use:
JUSTFILE_PATH="/path/to/external/justfiles/:./" just --list
This is my preferred solution for #1580 and while currently only implemented for imports, should work just as well for modules too, which might provide additional input or discussion points for #1799
I'm not set on the environment variable name, open for other suggestions.
Taking things slow as I'm fairly new to rust, but I think the idea should be clear 🙂