libyaml icon indicating copy to clipboard operation
libyaml copied to clipboard

Command-line utility

Open oxr463 opened this issue 5 years ago • 8 comments

It would be really helpful if there was a simple yaml command-line utility, similar to how this c-implementation of mustache templates includes a mustach tool.

See also: jq

oxr463 avatar Jun 14 '19 00:06 oxr463

What should the libyaml tool do?

perlpunk avatar Jun 14 '19 07:06 perlpunk

For starters, it could parse the examples,


echo  '
unqouted: string
literal-block: |
    This entire block of text will be the value of the 'literal-block' key,
    with line breaks being preserved.
folded: >
    This entire block of text will be the value of 'folded', but this
    time, all newlines will be replaced with a single space.
' | cyaml > strings.yml

Source: https://github.com/yaml/libyaml/blob/master/examples/strings.yaml

Adapted from: https://stackoverflow.com/a/31945335

oxr463 avatar Jun 14 '19 17:06 oxr463

Well, there are a couple of programs under the test/ directory. Of course currently they are only available if you build from source. They are not installed. With those tools you can do this for example:

tests/run-parser-test-suite file.yaml | tests/run-emitter-test-suite > newfile.yaml

I think having such a tool(set) installed with libyaml could be useful. I use the existing test tools often. @ingydotnet thoughts?

perlpunk avatar Jun 14 '19 21:06 perlpunk

Yes! Something like that would be great!

oxr463 avatar Jun 14 '19 22:06 oxr463

Sounds good to me.

ingydotnet avatar Jun 16 '19 03:06 ingydotnet

See also: https://github.com/pantoniou/libfyaml/blob/master/README.md#fy-tool-reference

oxr463 avatar May 05 '20 21:05 oxr463

Please consider exposing it during a package manager's post-install.

bash-5.0# apk add yaml
(1/1) Installing yaml (0.2.2-r1)
OK: 15 MiB in 30 packages
bash-5.0# yaml --help
bash: yaml: command not found
bash-5.0# which yaml
bash-5.0# 

I was expecting to be able to stream json to this tool, and get a yaml stream from it, and vice versa.

captain-kark avatar Jun 18 '20 20:06 captain-kark

Yeah, I would also like to have it. I just didn't find the time yet (and also have to learn how to create a binary to install)

perlpunk avatar Jun 18 '20 20:06 perlpunk