-
So I am once again asking for for your insight (please don't ban me, I <3 your Util) and I am once again expecting to discover new realms of my stupidity. ;-) general process: I have a default/template server.xml and other config files which I have a repeatable process of adding to/modifying based off of XYZ variables related to environment, application, user etc. Behold, my slightly familiar server.xml (example)
I would like to add another connector
but of course 'Connector' is not yet seen as an array yet (makes sense) and I get the response
basically many of the default/template config files I am modifying contain only one element as an example/default and when trying to make changes, I run into problems like this. Solutions?
or my ugly alternative...
at which point my previous command starts working as intended... and 'le problem' goes away
p.s. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey again Link, I'm glad you're getting some use out of dasel! The issue you're seeing here is because of this: https://daseldocs.tomwright.me/usage/supported-file-types#arrays-lists More specifically:
Dasel is reading your document as the following (in json form): {
"Server": {
"Service": {
"Connector": {
"-port": "123"
}
}
}
} Basically, your breakdown is correct. In many other data formats you would be expected to define the connectors as an array and this would then work entirely as expected, but since XML doesn't let you define something as an array we run into this issue. Is there an alternative method that is cleaner than what I am trying?I'd basically do what you suggested, but with the caveat that I'd extract value using dasel so you don't need to be aware of what it actually is: I would probably approach it like this: $ CONNECTOR=$(dasel -f file.xml -w json .Server.Service.Connector) Use put document to set connector to an array containing the extracted document... dasel put document -f file.xml -d json '.Server.Service.Connector' "[$CONNECTOR, {\"-port\":777}]" Any considerations for allowing a command which contains ...Connector.[] to add an additional 'Connector' even when it is not yet considered an array of Connectors?There is the potential to allow dasel to convert a single property into an array when the is this "abuse" of dasel, not common place and thus, a feature like this not needed/intended?This is the kind of problem I want to solve, but the incompatibility is more based on the differences between file formats rather than the data itself, so it's a hard problem to solve. The potential flag I mentioned above could be a good solution for this though! I can move my inquiries to another site like stackoverflowThere's no need for that at all! That's exactly what this Q&A section is for 🙂 |
Beta Was this translation helpful? Give feedback.
Hey again Link, I'm glad you're getting some use out of dasel!
The issue you're seeing here is because of this: https://daseldocs.tomwright.me/usage/supported-file-types#arrays-lists
More specifically:
Dasel is reading your document as the following (in json form):
Basically, your breakdown is correct.
In many other data formats you would be expected to define the connectors as an array and this would then work entirely as expected, but since XML doesn't let you define something as an…