-
Notifications
You must be signed in to change notification settings - Fork 31
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
Variable interpolation in the configuration file #71 #167
Conversation
adding initial structs for variable and includes parsing
Foremost. Thank you very much for the PR. It is much appreciated. I think this is implementation is good, although there are a few things I would like to change.
An example of that first point being. As far as I understand now, this is currently valid syntax. [variables]
a = 5
# ...
max_width = $a Although, this syntax would be nice to have, it is not really valid TOML syntax anymore. We would really want |
On the first point. The TOML syntax has to be valid in the first place, because we need a serde pass to parse the variables in the same file in the first place. Your example will produce an error at the point of trying to deserialize Basically, variables always have to be mentioned in quotes, and defined in the On the second point, true, I did say I considered it a quirky way to do it in the issue itself. On the third point. Yeah, in hindsight, I should have just done that, and will probably do so soon. |
I have added a variable iterator and removed the dependency on regex |
I apologize for coming back a bit late, I will look at this a bit later when I am less busy in other areas. |
This commit changes the method in which variables are supplied and parsed, requiring a separate file. For the configuration file, this is first parsed into a RoughConfig where variables might be inserted into any of the fields. Then, variables are interpreted into a PartialConfig.
Okay, finally got time to take a look at this. Foremost, thank you for this PR. I changed quite a bit, but I am pretty sure I would have not touched this in quite a long time had you not laid most of the groundwork. How it works now: There is an additional file
This way we don't have to manually change TOML files and can rely on the Again, thank you very much. I hope you will also use this feature yourself. |
Addresses #71
At this stage, now it's possible to have variables be properly substituted.
There are severe limitations to the way it is done in this PR.
Serde always expects a correct TOML for obvious reasons, so all variable mentions have to be in quotes for the toml to be formally correct.
At the time of substitution, quotes are added back for string type.
Due to the most of the options being on the top level, variable block has to be mentioned either on the bottom or alongside other blocks.
Example usage:
In configuration:
Due to the amount of changes, might need further work on error handling and control flow of configuration loading as well as a mention in README.md