From 2d7be26ad53c22d78eb05c1add71eaca9f045033 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 13 Jan 2020 16:58:11 +1100 Subject: [PATCH] wip update docs --- README.md | 2 +- docs/404.html | 12 + docs/convert/index.html | 33 +- docs/create/index.html | 82 +-- docs/delete/index.html | 261 +------ docs/index.html | 14 +- docs/merge/index.html | 13 +- docs/path_expressions/index.html | 862 +++++++++++++++++++++++ docs/prefix/index.html | 18 +- docs/read/index.html | 72 +- docs/search/search_index.json | 2 +- docs/sitemap.xml | 21 +- docs/sitemap.xml.gz | Bin 201 -> 201 bytes docs/snippets/niche/index.html | 447 ------------ docs/snippets/works_with_json/index.html | 385 ---------- docs/write/index.html | 72 +- examples/sample.yaml | 22 +- mkdocs.yml | 1 + mkdocs/convert.md | 28 +- mkdocs/create.md | 29 +- mkdocs/delete.md | 141 +--- mkdocs/index.md | 2 +- mkdocs/merge.md | 29 +- mkdocs/path_expressions.md | 208 ++++++ mkdocs/prefix.md | 39 +- mkdocs/read.md | 105 +-- mkdocs/snippets/niche.md | 35 - mkdocs/snippets/works_with_json.md | 1 - mkdocs/write.md | 137 +--- yq.go | 77 +- 30 files changed, 1401 insertions(+), 1749 deletions(-) create mode 100644 docs/path_expressions/index.html delete mode 100644 docs/snippets/niche/index.html delete mode 100644 docs/snippets/works_with_json/index.html create mode 100644 mkdocs/path_expressions.md delete mode 100644 mkdocs/snippets/niche.md delete mode 100644 mkdocs/snippets/works_with_json.md diff --git a/README.md b/README.md index 69f3c5df..c64d83e8 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ sudo apt install yq -y ``` ### or, [Download latest binary](https://github.com/mikefarah/yq/releases/latest) or alternatively: ``` -GO111MODULE=on go get github.com/mikefarah/yq/v2 +GO111MODULE=on go get github.com/mikefarah/yq/v3 ``` ## Run with Docker diff --git a/docs/404.html b/docs/404.html index d9cfab02..a6337614 100644 --- a/docs/404.html +++ b/docs/404.html @@ -248,6 +248,18 @@ +
  • + + Path Expressions + +
  • + + + + + + +
  • Write/Update diff --git a/docs/convert/index.html b/docs/convert/index.html index cc2f4922..7ed7ef07 100644 --- a/docs/convert/index.html +++ b/docs/convert/index.html @@ -252,6 +252,18 @@ +
  • + + Path Expressions + +
  • + + + + + + +
  • Write/Update @@ -414,20 +426,37 @@

    Convert

    Yaml to Json

    -

    To convert output to json, use the --tojson (or -j) flag. This can only be used with the read command.

    +

    To convert output to json, use the --tojson (or -j) flag. This is supported by all commands.

    +

    Each matching yaml node will be converted to json and printed out on a separate line.

    Given a sample.yaml file of:

    b:
       c: 2
     

    then

    -
    yq r -j sample.yaml b.c
    +
    yq r -j sample.yaml
     

    will output

    {"b":{"c":2}}
     
    +

    Given a sample.yaml file of:

    +
    bob:
    +  c: 2
    +bab:
    +  c: 5
    +
    + +

    then

    +
    yq r -j sample.yaml b*
    +
    + +

    will output

    +
    {"c":2}
    +{"c":5}
    +
    +

    Json to Yaml

    To read in json, just pass in a json file instead of yaml, it will just work :)

    e.g given a json file

    diff --git a/docs/create/index.html b/docs/create/index.html index 643060d3..7114b530 100644 --- a/docs/create/index.html +++ b/docs/create/index.html @@ -252,6 +252,18 @@ +
  • + + Path Expressions + +
  • + + + + + + +
  • Write/Update @@ -325,20 +337,6 @@
  • -
  • - - Keys with dots - - -
  • - -
  • - - Keys (and values) with leading dashes - - -
  • - @@ -406,20 +404,6 @@
  • -
  • - - Keys with dots - - -
  • - -
  • - - Keys (and values) with leading dashes - - -
  • - @@ -441,10 +425,11 @@

    Create

    -

    Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file.

    -
    yq n <path> <new value>
    +                
    yq n <path_expression> <new value>
     
    +

    Yaml files can be created using the 'new' command. This works in the same way as the write command, but you don't pass in an existing Yaml file. Currently this does not support creating multiple documents in a single yaml file.

    +

    See docs for path expression

    Creating a simple yaml file

    yq n b.c cat
     
    @@ -457,8 +442,11 @@

    Creating using a create script

    Create scripts follow the same format as the update scripts.

    Given a script create_instructions.yaml of:

    -
    b.c: 3
    -b.e[+].name: Howdy Partner
    +
    - command: update 
    +  path: b.c
    +  value:
    +    #great 
    +    things: frog # wow!
     

    then

    @@ -467,38 +455,14 @@ b.e[+].name: Howdy Partner

    will output:

    b:
    -  c: 3
    -  e:
    -    - name: Howdy Partner
    +  c:
    +    #great
    +    things: frog # wow!
     

    You can also pipe the instructions in:

    cat create_instructions.yaml | yq n -s -
     
    - -

    Keys with dots

    -

    When specifying a key that has a dot use key lookup indicator.

    -
    b:
    -  foo.bar: 7
    -
    - -
    yaml r sample.yaml 'b[foo.bar]'
    -
    - -
    yaml w sample.yaml 'b[foo.bar]' 9
    -
    - -

    Any valid yaml key can be specified as part of a key lookup.

    -

    Note that the path is in quotes to avoid the square brackets being interpreted by your shell.

    -

    Keys (and values) with leading dashes

    -

    If a key or value has leading dashes, yq won't know that you are passing a value as opposed to a flag (and you will get a 'bad flag syntax' error).

    -

    To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so:

    -
    yq n -t -- --key --value
    -
    - -

    Will result in

    -

    ` ---key: --value

    diff --git a/docs/delete/index.html b/docs/delete/index.html index e23d0abc..42b4d97f 100644 --- a/docs/delete/index.html +++ b/docs/delete/index.html @@ -94,7 +94,7 @@ - + Skip to content @@ -252,6 +252,18 @@ +
  • + + Path Expressions + +
  • + + + + + + +
  • Write/Update @@ -299,25 +311,11 @@