Discover Packages
github.com/DavidGamba/dgtools/yaml-parse
command
module
Version:
v0.3.1
Opens a new window with list of versions in this module.
Published: Mar 12, 2023
License: MPL-2.0
Opens a new window with license information.
Imports: 9
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
= yaml-parse
Parses YAML input passed from file or piped to STDIN and filters it by key or index
== Install
`$ go install github.com/DavidGamba/dgtools/yaml-parse@master`
== Examples
Given the following test data in the file `test_data/test.yaml`:
[source, yaml]
----
---
hello: world
array:
- element 1
- element 2
- element 3
array 2:
- key1: value1
- key2: value2
- key3: value3
number: 123
float: 123.123
bool: true
----
.Print all contents
----
$ yaml-parse test_data/test.yaml
array:
- element 1
- element 2
- element 3
array 2:
- key1: value1
- key2: value2
- key3: value3
bool: true
float: 123.123
hello: world
number: 123
----
.Print `array`
----
$ yaml-parse test_data/test.yaml -k array
- element 1
- element 2
- element 3
----
.Print `array` first element
----
$ yaml-parse test_data/test.yaml -k array -k 0
element 1
----
.Print `array 2`
----
$ yaml-parse test_data/test.yaml -k 'array 2'
- key1: value1
- key2: value2
- key3: value3
----
.Print `array 2` first element then map value
----
$ yaml-parse test_data/test.yaml -k 'array 2' -k 0 -k key1
value1
----
.Do the same with slash
----
$ yaml-parse test_data/test.yaml -k 'array 2/0/key1'
value1
----
.Add a json element to 'array 2'
----
$ yaml-parse test_data/test.yaml --add '{ hola: mundo }' -k 'array 2'
array:
- element 1
- element 2
- element 3
array 2:
- key1: value1
- key2: value2
- key3: value3
- hola: mundo
bool: true
float: 123.123
hello: world
number: 123
----
.Read the second document of a multi document YAML file
----
$ yaml-parse test_data/multiple.yaml -d 2
arreglo:
- elemento 1
- elemento 2
- elemento 3
arreglo 2:
- llave1: valor1
- llave2: valor2
- llave3: valor3
bool: true
float: 123.123
hola: mundo
numero: 123
----
Expand ▾
Collapse ▴
Documentation
¶
This file is part of dgtools.
Copyright (C) 2019-2023 David Gamba Rios ¶ This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/ .
Source Files
¶
Click to show internal directories.
Click to hide internal directories.