1FY-TOOL(1)                         libfyaml                         FY-TOOL(1)
2
3
4

NAME

6       fy-tool - fy-tool documentation
7

SYNOPSIS

9       fy-tool [OPTIONS] [<file> ...]
10
11       fy-dump [OPTIONS] [<file> ...]
12
13       fy-testsuite [OPTIONS] <file>
14
15       fy-filter [OPTIONS] [-f*FILE*] [<path> ...]
16
17       fy-join [OPTIONS] [-T*PATH*] [-F*PATH*] [-t*PATH*] [<file> ...]
18
19       fy-ypath [OPTIONS] <ypath-expression> [<*file> ...]
20
21       fy-compose [OPTIONS] [<file> ...]
22

DESCRIPTION

24       fy-tool  is  a general YAML/JSON manipulation tool using libfyaml.  Its
25       operation is different depending on how it's called, either via aliases
26       named  fy-dump,  fy-testsuite,  fy-filter,  fy-join, or via the --dump,
27       --testsuite, --filter, --join, --ypath and --compose options.
28
29       • In dump mode it will parse YAML/JSON input files and output YAML/JSON
30         according to the output format options.
31
32       • In  testsuite  mode it will parse a single YAML input file and output
33         yaml testsuite reference output.
34
35       • In filter mode it will parse YAML/JSON  files  and  output  YAML/JSON
36         output filtered according to the given option.
37
38       • In  join mode it will parse YAML/JSON files and join them into a sin‐
39         gle YAML/JSON document according to the given command line options.
40
41       • In ypath mode it will parse YAML/JSON files and execute a ypath query
42         which will output a document stream according to the results. This is
43         an experimental mode under development, where the syntax is  not  yet
44         decided completely.
45
46       • In compose mode, it operates similarly to dump, but the document tree
47         is created using the built-in composer API.
48

OPTIONS

50       A number of options are common for all the different modes of operation
51       and they are as follows: Common options.INDENT 0.0
52
53       -q, --quiet
54              Quiet operation, does not output informational messages at all.
55
56       -h, --help
57              Display usage information.
58
59       -v, --version
60              Display version information.
61
62       -I DIR, --include=DIR
63              Add  the DIR  directory to the search path which will be used to
64              locate a YAML/JSON file.  The default path is set to ""
65
66       -d LEVEL, --debug-level=LEVEL
67              Set the minimum numeric debug level  value  of  the  library  to
68              LEVEL.   The  numeric  value  must be in the range of 0 to 4 and
69              their meaning is as follows:
70
710 (DEBUG)
72
73                Internal library debugging messages.  No  output  is  produced
74                when the library was compiled with --disable-debug
75
761 (INFO)
77
78                Informational messages about the internal operation of the li‐
79                brary.
80
812 (NOTICE)
82
83                Messsages that could require attention.
84
853 (WARNING)
86
87                A warning message, something is wrong, but operation can  con‐
88                tinue.  This is the default value.
89
904 (ERROR)
91
92                A fatal error occured, it is impossible to continue.
93
94              The default level is 3 (WARNING), which means that messages with
95              level 3 and higher will be displayed.
96       Parser Options.INDENT 0.0
97
98       -j JSONOPT, --json=JSONOPT
99              Marks the input files as JSON or YAML accordingly to:
100
101no
102
103                The input files are always in YAML mode.
104
105force
106
107                The input files are always set to JSON mode.
108
109auto
110
111                The input files are set to JSON mode  automatically  when  the
112                file's extension is .json. This is the default.
113
114              JSON  support is complete so all valid JSON files are parsed ac‐
115              cording to JSON rules, even where those differ with YAML rules.
116
117       --yaml-1.1
118              Force YAML 1.1 rules, when input does not specify a version  via
119              a directive.
120
121       --yaml-1.2
122              Force  YAML 1.2 rules, when input does not specify a version via
123              a directive.
124
125       --yaml-1.3
126              Force YAML 1.3 rules, when input does not specify a version  via
127              a  directive.  This option is experimental since the 1.3 spec is
128              not yet released.
129
130       --disable-accel
131              Disable use of acceleration features; use less memory but poten‐
132              tially more CPU.
133
134       --disable-buffering
135              Disable  use  stdio bufferring, reads will be performed via unix
136              fd reads. This may reduce latency when reading  from  a  network
137              file descriptor, or similar.
138
139       --disable-depth-limit
140              Disable  the object depth limit, which is usually set to a value
141              near 60.  Using this option  is  is  possible  to  process  even
142              pathological  inputs  when using the default non-recursive build
143              mode.
144
145       --prefer-recursive
146              Prefer recursive build methods, instead of iterative. This field
147              is  merely here for evaluation purposes and will be removed in a
148              future version.
149
150       --sloppy-flow-indentation
151              Use sloppy flow indentation, where indentation is not taken into
152              account  in  flow  mode, even when the input is invalid YAML ac‐
153              cording to the spec.
154
155       --ypath-aliases
156              Process aliases using ypaths. Experimental option.
157
158       --streaming
159              Only valid when in dump mode, enables streaming mode. This means
160              that  no  in-memory graph tree is constructed, so indefinite and
161              arbitrary large YAML input streams can be processed.
162
163              Note that in streaming mode:
164
165              • Key duplication checks are disabled.
166
167              • No reording of key  order  is  possible  when  emitting  (i.e.
168                --sort is not available).
169
170              • Alias resolution is not available (i.e. --resolve).
171       Resolver Options.INDENT 0.0
172
173       -r, --resolve
174              Perform  anchor and merge key resolution. By default this option
175              is disabled.
176
177       -l, --follow
178              Follow aliases when performing path traversal. By  default  this
179              option is disabled.
180       Testsuite Options.INDENT 0.0
181
182       --disable-flow-markers
183              Do not output flow-markers for the testsuite output.
184Emitter Options.INDENT 0.0
185
186       -i INDENT, --indent=INDENT
187              Sets the emitter indent (in spaces). Default is 2.
188
189       -w WIDTH, --width=WIDTH
190              Sets  the preferred output width of the emitter. It is generally
191              impossible to strictly adhere to this limit so this  is  treated
192              as  a  hint  at  best.  It not valid in any oneline output modes
193              (i.e. flow-oneline or json-oneline).  Default value is 80.
194
195       -m MODE, --mode=MODE
196              Sets the output mode of the YAML emitted. Possible values are:
197
198original
199
200                The original formatting used in the  input.  This  is  default
201                mode.
202
203block
204
205                The  output is forced to be in block mode. All flow constructs
206                will be converted to block mode.
207
208flow
209
210                The output is forced to be in flow mode. All block  constructs
211                will be converted to flow mode.
212
213flow-oneline
214
215                The  output is forced to be in flow mode, but no newlines will
216                be emitted; the output is going to  be  a  (potentially  very)
217                long line.
218
219json
220
221                The  output  is forced to be in JSON mode. Note that it is im‐
222                possible to output an arbitrary YAML file as JSON, so this may
223                fail.
224
225json-oneline
226
227                The output is forced to be in JSON mode and in a single line.
228
229dejson
230
231                Output  is in block YAML mode but with special care to convert
232                JSON quoted strings in as non-idiomatic YAML as possible.  For
233                example { foo: "this is a test" } will be emitted as foo: this
234                is a test. YAML can handle  scalars  without  using  excessive
235                quoting.
236
237       -C MODE, --color=MODE
238              It  is  possible  to colorize output using ANSI color escape se‐
239              quences, and the mode can be one of:
240
241off
242
243                Never colorize output.
244
245on
246
247                Always colorize output.
248
249auto
250
251                Automatically colorize output when the output is  a  terminal.
252                This is the default.
253
254       -V, --visible
255              Make all whitespace (spaces, unicode spaces and linebreaks) vis‐
256              ible.  Note that this is performed using UTF8 characters  so  it
257              will  not  work  on  non-UTF8  terminals, or a non-UTF8 complete
258              font.
259
260       -s, --sort
261              Sort keys on output. This option is disabled by default.
262
263       -c, --comment
264              Experimental output comments option. Enabled output  while  pre‐
265              serving comments.  Disabled by default.
266
267       --strip-labels
268              Strip labels on output. Disabled by default.
269
270       --strip-tags
271              Strip tags on output. Disabled by default.
272
273       --strip-doc
274              Strip document indicators on output. Disabled by default.
275
276       --null-output
277              Do not generate any output, useful for profiling the parser.
278       YPATH options.INDENT 0.0
279
280       --dump-pathexpr
281              Dump the produced path expression for debugging.
282
283       --no-exec
284              Do   not   execute   the   expression.  Useful  when  used  with
285              --dump-pathexpr
286       Compose options.INDENT 0.0
287
288       --dump-path
289              Dump the path while composing.
290Tool mode select options.INDENT 0.0
291
292       --dump Select dump mode of operation. This is the default.   This  mode
293              is also enabled when the called binary is aliased to fy-dump.
294
295              In  this  mode,  all  files provided in the command line will be
296              dumped in one continuous stream, to the standard  output,  using
297              document start indicators to mark the start of end new file.
298
299              If the file provided is - then the input is the standard input.
300
301       --testsuite
302              Select  testsuite  mode of operation.  This mode is also enabled
303              when the called binary is aliased to fy-testsuite.
304
305              In this mode, a single YAML file is read and an event stream  is
306              generated  which  is  the format used for yaml-testsuite compli‐
307              ance.
308
309              If the file provided is - then the input is the standard input.
310
311       --filter
312              Select filter mode of operation.  This mode is also enabled when
313              the called binary is aliased to fy-filter.
314
315              In this mode, a single YAML file is read from the standard input
316              for each path that is provided in the command  line  a  document
317              will be produced to the standard output.  To use file instead of
318              standard input use the -f/--file option.
319
320              If the file provided is - then the input is the standard input.
321
322              -f FILE, --file=FILE
323                     Use the given file as input instead of standard input.
324
325                     If  first character of FILE is > the  the  input  is  the
326                     content  of  the option that follows.  For example --file
327                     ">foo: bar" is as --file file.yaml with  file.yaml  "foo:
328                     bar"
329
330       --join Select  join  mode of operation.  This mode is also enabled when
331              the called binary is aliased to fy-join.
332
333              In this mode, multiple YAML files are joined into a single docu‐
334              ment, emitted to the standard output.
335
336              If the file provided is - then the input is the standard input.
337
338              -T PATH, --to=PATH
339                     The  target path of the join. By default this is the root
340                     /.
341
342                     If  first character of FILE is > the  the  input  is  the
343                     content of the option that follows.
344
345              -F PATH, --from=PATH
346                     The  origin path of the join (for each input). By default
347                     this is the root /.
348
349                     If  first character of FILE is > the  the  input  is  the
350                     content of the option that follows.
351
352              -t PATH, --trim=PATH
353                     Trim  path  of the output of the join. By default this is
354                     the root /.
355
356                     If  first character of FILE is > the  the  input  is  the
357                     content of the option that follows.
358
359       --ypath
360              Process files and output query results using ypath.
361
362       --compose
363              Use  the  composer  API  to build the document instead of direct
364              events.
365

EXAMPLES

367       Example input files
368
369       We're going to be using a couple of YAML files in our examples.
370
371       invoice.yaml
372
373          # invoice.yaml
374          invoice: 34843
375          date   : !!str 2001-01-23
376          bill-to: &id001
377          given  : Chris
378          family : Dumars
379          address:
380                  lines: |
381                  458 Walkman Dr.
382                  Suite #292
383
384       simple-anchors.yaml
385
386          # simple-anchors.yaml
387          foo: &label { bar: frooz }
388          baz: *label
389
390       mergekeyspec.yaml
391
392          ---
393          - &CENTER { x: 1, y: 2 }
394          - &LEFT { x: 0, y: 2 }
395          - &BIG { r: 10 }
396          - &SMALL { r: 1 }
397
398          # All the following maps are equal:
399
400          - # Explicit keys
401            x: 1
402            y: 2
403            r: 10
404            label: center/big
405
406          - # Merge one map
407            << : *CENTER
408            r: 10
409            label: center/big
410
411          - # Merge multiple maps
412            << : [ *CENTER, *BIG ]
413            label: center/big
414
415          - # Override
416            << : [ *BIG, *LEFT, *SMALL ]
417            x: 1
418            label: center/big
419
420       bomb.yaml
421
422          a: &a ["lol","lol","lol","lol","lol","lol","lol","lol","lol"]
423          b: &b [*a,*a,*a,*a,*a,*a,*a,*a,*a]
424          c: &c [*b,*b,*b,*b,*b,*b,*b,*b,*b]
425          d: &d [*c,*c,*c,*c,*c,*c,*c,*c,*c]
426          e: &e [*d,*d,*d,*d,*d,*d,*d,*d,*d]
427          f: &f [*e,*e,*e,*e,*e,*e,*e,*e,*e]
428          g: &g [*f,*f,*f,*f,*f,*f,*f,*f,*f]
429       fy-dump examples.
430
431       Parse and dump generated YAML document tree in the original YAML form
432
433          $ fy-dump invoice.yaml
434
435          invoice: 34843
436          date: !!str 2001-01-23
437          bill-to: &id001
438          given: Chris
439          family: Dumars
440            address:
441            lines: |
442              458 Walkman Dr.
443              Suite #292
444
445       Parse and dump generated YAML document tree in flow YAML form
446
447          $ fy-dump -mflow invoice.yaml
448
449          {
450            invoice: 34843,
451            date: !!str 2001-01-23,
452            bill-to: &id001 {
453              given: Chris,
454              family: Dumars,
455              address: {
456                lines: "458 Walkman Dr.\nSuite #292\n"
457              }
458            }
459          }
460
461       Parse and dump generated YAML document from the input string
462
463          $ fy-dump -mjson ">foo: bar"
464
465          {
466            "foo": "bar"
467          }
468
469       Using the resolve option on the simple-anchors.yaml
470
471          $ fy-dump -r simple-anchor.yaml
472
473          foo: &label {
474              bar: frooz
475            }
476          baz: {
477              bar: frooz
478            }
479
480       Stripping the labels too:
481
482          $ fy-dump -r --strip-label simple-anchor.yaml
483
484          foo: {
485              bar: frooz
486            }
487          baz: {
488              bar: frooz
489            }
490
491       Merge key support:
492
493          $ fy-dump -r --strip-label mergekeyspec.yaml
494
495          ---
496          - {
497              x: 1,
498              y: 2
499            }
500          - {
501              x: 0,
502              y: 2
503            }
504          - {
505              r: 10
506            }
507          - {
508              r: 1
509            }
510          - x: 1
511            y: 2
512            r: 10
513            label: center/big
514          - y: 2
515            x: 1
516            r: 10
517            label: center/big
518          - r: 10
519            y: 2
520            x: 1
521            label: center/big
522          - y: 2
523            r: 10
524            x: 1
525            label: center/big
526
527       Sorting option:
528
529          $ fy-dump -s invoice.yaml
530
531          bill-to: &id001
532            address:
533              lines: |
534                458 Walkman Dr.
535                Suite #292
536            family: Dumars
537            given: Chris
538          date: !!str 2001-01-23
539          invoice: 34843
540       fy-testsuite example.
541
542       An example using the  testsuite  mode  generates  the  following  event
543       stream from invoice.yaml
544
545       Parse and dump test-suite event format
546
547          $ fy-testsuite invoice.yaml
548       fy-filter examples.
549
550       Filter out from the /bill-to path of invoice.yaml
551
552          $ cat invoice.yaml | fy-filter /bill-to
553
554          &id001
555          given: Chris
556          family: Dumars
557          address:
558            lines: |
559              458 Walkman Dr.
560              Suite #292
561
562       Filter example with arrays (and use the --file option)
563
564          $ fy-filter --file=mergekeyspec.yaml /5
565
566          ---
567          <<: *CENTER
568          r: 10
569          label: center/big
570
571       Follow anchors example
572
573          $ fy-filter --file=simple-anchors.yaml /baz/bar
574
575          frooz
576
577       Handle YAML bombs (if you can spare the memory and cpu time)
578
579          $ fy-filter --file=bomb.yaml -r / | wc -l
580          6726047
581
582       You don't have to, you can just follow links to retrieve data.
583
584          $ fy-filter --file=stuff/bomb.yaml -l --strip-label /g/0/1/2/3/4/5/6
585
586          "lol"
587
588       Following links works with merge keys too:
589
590          $ fy-filter --file=mergekeyspec.yaml -l --strip-label /5/x
591
592          --- 1
593       fy-join examples.
594
595       Joining two YAML files that have root mappings.
596
597          $ fy-join simple-anchors.yaml invoice.yaml
598
599          foo: &label {
600              bar: frooz
601            }
602          baz: *label
603          invoice: 34843
604          date: !!str 2001-01-23
605          bill-to: &id001
606            given: Chris
607            family: Dumars
608            address:
609              lines: |
610                458 Walkman Dr.
611                Suite #292
612
613       Join two files with sequences at root:
614
615          $ fy-join -mblock ">[ foo, bar ]" ">[ baz ]"
616
617          - foo
618          - bar
619          - baz
620

AUTHOR

622       Pantelis Antoniou <pantelis.antoniou@konsulko.com>
623

BUGS

625       • The only supported input and output character encoding is UTF8.
626
627       • Sorting does not respect language settings.
628
629       • There is no way for the user to specific a different coloring scheme.
630

SEE ALSO

632       libfyaml(1)
633
635       2019, Pantelis Antoniou
636
637
638
639
640                                 Jan 14, 2022                       FY-TOOL(1)
Impressum