-
Notifications
You must be signed in to change notification settings - Fork 476
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
Load variables from config files #460
Comments
Although written in Rust, Just is in general language agnostic, so I'm hesitant to add any language-specific features. Can you give some examples of parameters you'd like to have access to your justfiles? |
Like, for example, the project name/version. I was not aware that Just is language-agnostic. Another idea is to make it possible to load any .toml or config file through just and use the variables inside. |
I think that's a good way to do it, i.e. letting users load arbitrary TOML files. Indeed, Just's justfile parses This feature requires a few things:
For 1 and 3, it might look like this: # the file extension, `.toml` makes Just interpret the file as TOML
# the file stem, `foo`, determines the name of object containing the loaded variables
load "foo.toml"
# equivalently but more explicitly
foo = load("foo.toml", "toml")
# (however, the above would present difficulties, because it implies that a function can return something other than a string)
# variables can be retrieved from the `foo` object using dot notation
bar:
echo {{foo.bar}}
echo {{foo.baz.buzz}} Since TOML files can contain values that are not strings, e.g. floating point numbers, lists, and table, and the only kind of values in Just are strings, we'd need to figure out how to bridge the gap. As an MVP, I think I might only allow accessing string values, since they require no conversion. Then, later, when we have more experience with the feature, we can figure out what the right thing to do with other types is. |
You just gave me a solution @casey. Haha, Thanks but I agree that parsing can be challenging and add more complexity to the program. Is there some parsers implemented in pure Bash? |
Actually, since there is already a good TOML parser in rust, the parsing part shouldn't be too hard. I couldn't find any TOML parsers in pure Bash, only this one, which has a shell interface but is written in Go. |
Before going the I think it would be clever to separate the config value usage into two areas:
|
@dennschu Those are totally fair comments!
I wouldn't want to support TOML only, but want to limit the number of formats supported in the MVP, so doing TOML first seems reasonable.
Multiple sources by having declaration lines that bring a name into scope that represents that source, and a common notation for accessing properties:
Does that sound reasonable? |
The types supported could be limited to what the ecosystem has in term of stable libraries and Serde support. My understanding is that you need some kind of Serde adapter and then you can support easily any other type given that a library for that exists? |
The issue with types has more to do with Just's type system than available crates and Serde support. Currently, just only has one type of value, strings. I would like to introduce additional types, so that the language can be expanded However, I dislike dynamic type systems, so the introduction of a second type will require adding a static type system to Just, and who knows when I'll get around to that 😅 |
*I meant file type. I don't think there is a reason to implement types for bash instructions. It'd be helpful for quite advanced situation but that might not be the best focus for Just now? |
Right, for file types, anything with a high quality parser and serde support will be easy. My concern is that if I implement a dynamic type system it will be very hard to move to a static type system in backwards compatible way. And, my prior is that static typing is useful even for small programs. |
Does just load the cargo.toml file so that I can access parameters like the project name, version, etc...
I find it redundant to put these parameters in both cargo.toml and a .env file. It is better to have them in one location.
The text was updated successfully, but these errors were encountered: