Skip to content
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

Feature request: comment out parts of the yaml output #680

Open
royhadad opened this issue Aug 6, 2022 · 0 comments
Open

Feature request: comment out parts of the yaml output #680

royhadad opened this issue Aug 6, 2022 · 0 comments

Comments

@royhadad
Copy link

royhadad commented Aug 6, 2022

Context:
Let's say you need to generate a config yaml file for users, but you want some of the config options to be commented out.
This way your users can easily comment in and out some of the config options.
The feature needed is a way to tell the js-yaml parser what items to comment out (items of an array OR key-value pairs of an object)

To the best of my knowledge, this will be the first library that implements this kind of feature, I could not find it anywhere else.

Real world use case:
I've already implemented this behavior for my company, it can be viewed by going to https://app.datree.io/settings/user-settings (after signup) and clicking on Download policies.yaml

API suggestion:

  1. Have a flag option: withComments: boolean [default: false]
  2. Every time a JSON array has an item that equals to "JS_YAML_ARRAY_START_COMMENTS" - array items will start to be commented out.
  3. Every time a JSON array has an item that equals "JS_YAML_ARRAY_STOP_COMMENTS" - array items will stop being commented out.
  4. Every time an object has a key that equals "JS_YAML_OBJECT_COMMENTS" - the value of that key should be a string, comma-separated list of keys to comment out of the current object.
  5. All special indicators (e.g "JS_YAML_ARRAY_START_COMMENTS") should be removed for the final yaml output.

Implementation:
As I've stated, I already implemented the specific use case for my company as a wrapper to this library, it should be possible to implement it for the general use case as well.
That being said, this is definitely tricky and should be marked as an experimental feature.

Wrap up:

  1. Is this something that given a working implementation, will be accepted to the library?
  2. Any concerns/suggestions regarding the suggested API?
  3. Any concerns regarding the implementation?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant