Closed am21 closed 3 years ago
You are absolutely right. I hastily added delete and null capabilities directly to the CLI tool to meet an immediate need in that context. Limited by that frame of mind, I completely overlooked library users.
Your idea of adding node management capabilities directly to the NodeCoords class is intriguing. I will consider the options and take this ticket as an enhancement request.
Thank you!
Intriguing, right ... I didn't put too much thought in it when I opened the issue ;-) If you find a better way, by all means ..
I went down a deep rabbit hole while looking into this idea of extending NodeCoords for direct data manipulation. I'm going to shelve that idea for a later major version change. I will instead implement your request as the library extension I should have originally added.
Sorry for the long delay.
No worries. Sorry I sent you down that rabbit hole ... on the other hand, I always find it interesting to look critically at an API and try things. Thanks in advance for the upcoming fix.
PR #115 resolves this request. The syntax for deleting via the library will be a bit different from your original request due to the nature of how Python Generators work; your code must consume each deleted node for the node to actually be deleted. In trade, you get the node before it is deleted for tracking, analysis, restoration, relocation, or whatever you might do with the deleted data.
A code example is in one of the new tests for this capability: https://github.com/wwkimball/yamlpath/blob/development/tests/test_processor.py#L811-L814
The next two code blocks in that test (1) verify the deleted nodes were as expected and (2) verify the remaining document still contains all other expected nodes.
These changes will be in the next release pursuant to https://github.com/wwkimball/yamlpath/projects/1
The only way to delete nodes now is with
yaml-set
command line. Would be really nice to have the functionality in ayamlpath
function somehow. Maybe from the node itself, so we could write:Or maybe there is already a simple to do it and I missed it?