pantoniou / libfyaml

Fully feature complete YAML parser and emitter, supporting the latest YAML spec and passing the full YAML testsuite.
MIT License
239 stars 73 forks source link

Does fy-tool allow modifying and deleting keys? #114

Closed hq6 closed 1 month ago

hq6 commented 1 month ago

The documentation states a filter option, but there are no examples of replacing the value for a key with another, or deleting an entire key or set of keys by regex or glob pattern.

Is there support for these operations in either the library or the tool?

I'm looking for functionality similar to what yq supports, but without messing up formating like yq does.

pantoniou commented 1 month ago

Fixed in 13fc5ac6e4f0362cdd982875dbfd2e51091126b2

hq6 commented 1 month ago

@pantoniou Thanks for fixing the library!

However, I'm still interested in whether the CLI tool supports this out of the box.

Could you address this question explicitly either here or in the docs?

pantoniou commented 1 month ago

There's a WIP ypath implementation using the --ypath switch. It's quite experimental right now, and although it supports expressions, it doesn't support negation yet for filtering out nodes.

I might be able to take a stab at what you want, what kind of yq subset do you need? Note that the syntax will be different.

hq6 commented 1 month ago

I don't really need the fancy transformations. Just the following would make it super useful:

  1. Be able to delete keys whose path matches either glob or regex pattern.
    • Example: Delete all keys at paths matching "metadata.annotations.*".
  2. Be able to delete items in a sequence either by index, or which satisfies some condition:
    • Example: Delete the items of spec.containers[0].env which have a key called name and a value called HTTP_PROXY.
  3. Be able to upsert the value at arbitrary paths, creating parents as needed, and replacing if already exists.