Open vaab opened 5 months ago
And of course, many thanks for this new lib that is more than welcome !
Also, as a consequence of libfyaml
not parsing for different types of scalar (AFAIK), there are no distinction made between an empty node and an empty stringed value... As food for though:
Libyaml:
$ echo "a: " | shyaml get-value -y a
null
$ echo "a: ''" | shyaml get-value -y a
''
yq:
$ echo "a: " | yq -r=false '.a' ## humm, suprising answer
$ echo "a: " | yq '.a | type'
!!null
$ echo "" | yq '. | type' ## but consistent
!!null
$ echo "a: ''" | yq -r=false '.a'
''
$ echo "a: ''" | yq '.a | type'
!!str
Yes, all these are a consequence of libfyaml currently only supporting the builtin schema (where all scalars are strings). There is work underway to support the default object schemas (and more) but it's not on master yet.
Leaving this open for now, and will revisit later
Hi, I've been using
libyaml
,yq
, andlibfyaml
, and I noticed the existence of the pretty mode inlibfyaml
, which might not be exactly what I expected it was, so I wonder what are the intentions and responsibility of this mode. Let me clarify also my understanding to this point. I know there are many inconsistencies between tools, some are intentional, and others are bugs or functionality yet to be implemented.Let's start with creating this yaml code:
Notice several points:
!e!bar
!myobj
tag.{}
,[]
!!
is refering here to standard prefix, and to take one example!!str
is the default type of a scalar that would be parsed as a string.!!timestamp
(foryq
for instance and not a!!str
, and a!!date
forlibyaml
). More on that later.Here is the prettified version of this code using
yq -P /tmp/test.yaml
:Here is the prettified version of this code using
cat /tmp/test.yaml | shyaml get-value
(this is a python wrapper aroundlibyaml
):We notice that it is very similar, and that's encouraging. And they went both through:
!!str
type of "2010-01-01" that would be interpreted as a!!timestamp
foryq
, or a!!date
forlibyaml
if the!!str
and the double quotes where removed.!myobj
and!!foo
Using
fy-tool --dump -mode pretty /tmp/test.yaml
:We notice it is properly:
{}
around maps, and[]
around sequences and using the yaml representation)But it doesn't:
!!str
,!!map
,!!seq
where they are redundant.If keeping the tag directive doesn't sound problematic, as the YAML doc is still complete, it means that devs should not think that
fy_emit_node_to_string(..)
is complete by itself. They should not forget to usefy_emit_document_start(..)
before.Would you welcome some PR to move on some (or all) of these points ? Or want to share your stance on these topics ?
!!str
/!!map
/... if it is redundant (beware, this means that further parsing needs to be done, as many types are not implemented yet inlibfyaml
AFAIK, like!!timestamp
)fy_emit_node_to_string(..)
to be independant from a document start.I already have some work done on these.
I'm sure also that I missed important information about these... so feel free to correct me.