-
Notifications
You must be signed in to change notification settings - Fork 858
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 + in key names #644
Comments
Dashes can already be used in bare keys, including at the beginnings of key names. So we're just talking about the plus signs here. That said, I'm up-and-down about this proposal. The simplest approach to fulfilling this enhancement request would be to add plus signs (" This is being requested so that a file for an application intended to alter an existing configuration can also be written easily as TOML. But color me skeptical about making such documents easier to write. Since an application to make modifications to existing configs is certainly an extraordinary application, I am not sure if we ought to make it easier, just for that purpose. |
Right Dave, The easiest way to accomplish what I need is to add "+" as an allowed character. I'm not sure what the disadvantages of doing that are. I read through #283 and all the issues it links to. I understand originally keys could contain anything, then it was proposed to restrict them to alpha-numeric only, but dashes were added because the Rust people needed them for Cargo. Adding + seems easy enough, but it could be a 'slippery slope' to allowing any character again. |
Adding "+" as an allowed character feels pretty safe and reasonable to me. Besides this (obscure) use case it might also come handy in many other situations, allowing designers to name their keys "apples+oranges", "Musicians+Artists" etc. I don't think that we risk a "'slippery slope" as long as the allowed characters remain limited to those printed on the keycaps of a standard US QWERTY keyboard. |
Can I propose an alternative? Wouldn't it work to make use of the following configuration style, which IMO also makes it more clear to the reader what you're doing with the data? ("a + or - at the start of the key has special meaning" only works for those who are familiar with the configuration system already: [table]
key.add = [ "These elements", " are added to an existing key" ]
key.remove = [ "These elements", " are removed from an existing key" ] this style also allows for many other typical schemes that you might come up with during configuration management-like tasks, for example: [table]
key.replace = { search="$HOSTNAME", replace="production.example.com" }
key.insert = [ "tier1.example.com" ] # insert items at the start of the array
key.append = [ "tierx1.example.com", "tierx2.example.com" ] # append items to the end
key.dictFromQuery = "SELECT key, value FROM configuration WHERE env='production'"
key.unset = true
# ... etc ... Wouldn't these be more clear than the special meaning of "+" and "-" ?
|
Good idea Maurice. In our particular system, the order of the arrays doesn't matter, but I can easily imagine systems where it does. So, it's now much less important for my use case, but it might still be useful to support "+" in key names as Christian points out. At this point it's rehashing the arguments from #283 et al. |
The + can be added easy enough, but the thing is: where does that end? In fact, the whole unicode space, except for the = sign and spaces might be considered useful to support.If + is useful, why not add for example %, & and * as well and what would be good reasons for adding additional characters? Slippery slope IMO. But luckily not my slippery slope ;-) I like the bare key formatting as-is, since it does force one to use a simple naming scheme. However, when more elaborate naming is required, escaping the constraints by adding a few quotes does the trick. |
At this point, I suggest we defer until v1.0 has been released. The addition of plus signs to bare keys isn't urgent, but may still be valuable. |
Hmm... I definitely don't think this is a good idea for a key. Anyway, I'm gonna squat behind "I want to get 1.0 ready first" and defer on deciding about this for later. One thing I know for sure is that there's no slippery slope here -- |
If added for the sake of the + sign being parsed as an addition operator, I believe this adds semantic confusion and drifts towards encouraging people to parse particular key names in a particular way, rather than as what they are, names. The same does not exist for supporting it purely for its own sake, but I believe the wisdom of maintaining a deeply restricted syntax for bare key names continues to apply. The current selection of bare key legal characters encourages restricting ourselves to US-ASCII, and, better yet, URL-safe characters, preferably non-reserved ones. Of those, only a few aren't legal and also haven't been granted a meaning or permitted in bare keys already. So, I suppose I would have to put forward an argument for the tilde, |
Ok, spending some time to think through this -- @mmakaay's suggestion is a good one and I think @workingjubilee's point around not adding semantics to the keys (rather than treating them as a name) is a good one as well. I think not expanding beyond |
I'm working on a system that allows for merging TOML files together. For example you could have a "Base" config and a platform specific "Override" config.
For scalars it's easy -- overwrite the old value. For arrays it's tricky though because we want the ability to add and remove elements.
I'd like the ability to prefix a key or table name with + to indicate it should be added to an existing array, or - to indicate it should be removed. For example:
[table]
+key=[ "These elements", " are added to an existing key" ]
-key=[ "These elements", " are removed from an existing key" ]
I can do it right now by enclosing the name in quotes, but it would be really nice to specify them with bare keys.
Alternatively, TOML could support explicit merging with += and -= operators, but that seems like a much bigger change.
The text was updated successfully, but these errors were encountered: