ABridoux / scout

Reading and writing in JSON, Plist, YAML and XML data made simple when the data format is not known at build time. Swift library and command-line tool.
https://www.woodys-findings.com/scout
MIT License
130 stars 6 forks source link

How to duplicate an item #137

Open mikedowler opened 4 years ago

mikedowler commented 4 years ago

I'd like to be able to add an new entry which duplicates all the properties of an existing entry. For example, using people.json, I'd like to create Tom's evil twin, evilTom.

I can't pass a reference to an existing entry: scout add -i /tmp/people.json "people.evilTom=people.Tom" merely adds the string "people.Tom" to evilTom.

Capturing the output of Tom to a variable first: tom=$(scout read -i /tmp/people.json "people.Tom") is fine, but then adding it to a new entry scout add -i /tmp/people.json "people.evilTom=$tom" simply adds it as a text string, meaning it can no longer be parsed.

It seems like the only option is to read each individual property (which requires knowledge of the datatype of that property) and then write that individual property to the new location. I feel like this is a task which ought to be much easier in Scout, but would actually be easier with a text parser. Am I missing something?

ABridoux commented 4 years ago

That's not a use case I had in mind to add a value, as Scout was primarily designed to change one single value at a time. Here, it's a group value that you want to change. So it's not possible to do it for now, sadly. But that's a really interesting feature and this can be bundled in a future release. I am marking this issue as an enhancement.