mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 05:38:04 +00:00
Updated docs to include value parsing
This commit is contained in:
parent
b7148adf20
commit
8a65822b0b
@ -237,8 +237,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
<a href="/path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -249,8 +249,20 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
<a href="/value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="/read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
@ -241,8 +241,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -253,8 +253,20 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -425,7 +437,7 @@
|
||||
|
||||
<h1>Convert</h1>
|
||||
|
||||
<h3 id="yaml-to-json">Yaml to Json<a class="headerlink" href="#yaml-to-json" title="Permanent link">¶</a></h3>
|
||||
<h2 id="yaml-to-json">Yaml to Json<a class="headerlink" href="#yaml-to-json" title="Permanent link">¶</a></h2>
|
||||
<p>To convert output to json, use the --tojson (or -j) flag. This is supported by all commands.</p>
|
||||
<p>Each matching yaml node will be converted to json and printed out on a separate line.</p>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
@ -457,7 +469,7 @@ bab:
|
||||
{"c":5}
|
||||
</code></pre>
|
||||
|
||||
<h3 id="json-to-yaml">Json to Yaml<a class="headerlink" href="#json-to-yaml" title="Permanent link">¶</a></h3>
|
||||
<h2 id="json-to-yaml">Json to Yaml<a class="headerlink" href="#json-to-yaml" title="Permanent link">¶</a></h2>
|
||||
<p>To read in json, just pass in a json file instead of yaml, it will just work :)</p>
|
||||
<p>e.g given a json file</p>
|
||||
<pre><code class="json">{"a":"Easy! as one two three","b":{"c":2,"d":[3,4]}}
|
||||
|
@ -241,8 +241,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -253,8 +253,20 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -430,7 +442,7 @@
|
||||
|
||||
<p>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.</p>
|
||||
<p>See docs for <a href="../path_expressions/">path expression</a></p>
|
||||
<h3 id="creating-a-simple-yaml-file">Creating a simple yaml file<a class="headerlink" href="#creating-a-simple-yaml-file" title="Permanent link">¶</a></h3>
|
||||
<h2 id="creating-a-simple-yaml-file">Creating a simple yaml file<a class="headerlink" href="#creating-a-simple-yaml-file" title="Permanent link">¶</a></h2>
|
||||
<pre><code class="bash">yq n b.c cat
|
||||
</code></pre>
|
||||
|
||||
@ -439,7 +451,7 @@
|
||||
c: cat
|
||||
</code></pre>
|
||||
|
||||
<h3 id="creating-using-a-create-script">Creating using a create script<a class="headerlink" href="#creating-using-a-create-script" title="Permanent link">¶</a></h3>
|
||||
<h2 id="creating-using-a-create-script">Creating using a create script<a class="headerlink" href="#creating-using-a-create-script" title="Permanent link">¶</a></h2>
|
||||
<p>Create scripts follow the same format as the update scripts.</p>
|
||||
<p>Given a script create_instructions.yaml of:</p>
|
||||
<pre><code class="yaml">- command: update
|
||||
|
@ -94,7 +94,7 @@
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#from-stdin" tabindex="1" class="md-skip">
|
||||
<a href="#deleting-from-a-simple-document" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
@ -241,8 +241,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -253,8 +253,20 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -311,6 +323,13 @@
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#deleting-from-a-simple-document" title="Deleting from a simple document" class="md-nav__link">
|
||||
Deleting from a simple document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#from-stdin" title="From STDIN" class="md-nav__link">
|
||||
From STDIN
|
||||
@ -319,25 +338,38 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#deleting-nodes-in-place" title="Deleting nodes in-place" class="md-nav__link">
|
||||
Deleting nodes in-place
|
||||
<a href="#deleting-in-place" title="Deleting in-place" class="md-nav__link">
|
||||
Deleting in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-delete-from-single-document" title="Multiple Documents - delete from single document" class="md-nav__link">
|
||||
Multiple Documents - delete from single document
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#delete-from-single-document" title="Delete from single document" class="md-nav__link">
|
||||
Delete from single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-delete-from-all-documents" title="Multiple Documents - delete from all documents" class="md-nav__link">
|
||||
Multiple Documents - delete from all documents
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#delete-from-all-documents" title="Delete from all documents" class="md-nav__link">
|
||||
Delete from all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
@ -404,6 +436,13 @@
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#deleting-from-a-simple-document" title="Deleting from a simple document" class="md-nav__link">
|
||||
Deleting from a simple document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#from-stdin" title="From STDIN" class="md-nav__link">
|
||||
From STDIN
|
||||
@ -412,25 +451,38 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#deleting-nodes-in-place" title="Deleting nodes in-place" class="md-nav__link">
|
||||
Deleting nodes in-place
|
||||
<a href="#deleting-in-place" title="Deleting in-place" class="md-nav__link">
|
||||
Deleting in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-delete-from-single-document" title="Multiple Documents - delete from single document" class="md-nav__link">
|
||||
Multiple Documents - delete from single document
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#delete-from-single-document" title="Delete from single document" class="md-nav__link">
|
||||
Delete from single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-delete-from-all-documents" title="Multiple Documents - delete from all documents" class="md-nav__link">
|
||||
Multiple Documents - delete from all documents
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#delete-from-all-documents" title="Delete from all documents" class="md-nav__link">
|
||||
Delete from all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
@ -458,12 +510,7 @@
|
||||
|
||||
<p>The delete command will delete all the matching nodes for the path expression in the given yaml input.</p>
|
||||
<p>See docs for <a href="../path_expressions/">path expression</a> for more details.</p>
|
||||
<h3 id="from-stdin">From STDIN<a class="headerlink" href="#from-stdin" title="Permanent link">¶</a></h3>
|
||||
<p>Use "-" (without quotes) inplace of a file name if you wish to pipe in input from STDIN.</p>
|
||||
<pre><code class="bash">cat sample.yaml | yq d - b.c
|
||||
</code></pre>
|
||||
|
||||
<h3 id="deleting-nodes-in-place">Deleting nodes in-place<a class="headerlink" href="#deleting-nodes-in-place" title="Permanent link">¶</a></h3>
|
||||
<h2 id="deleting-from-a-simple-document">Deleting from a simple document<a class="headerlink" href="#deleting-from-a-simple-document" title="Permanent link">¶</a></h2>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
@ -471,11 +518,26 @@
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq d sample.yaml b.c
|
||||
</code></pre>
|
||||
|
||||
<p>will output</p>
|
||||
<pre><code class="yaml">b:
|
||||
apples: green
|
||||
</code></pre>
|
||||
|
||||
<h2 id="from-stdin">From STDIN<a class="headerlink" href="#from-stdin" title="Permanent link">¶</a></h2>
|
||||
<p>Use "-" (without quotes) in-place of a file name if you wish to pipe in input from STDIN.</p>
|
||||
<pre><code class="bash">cat sample.yaml | yq d - b.c
|
||||
</code></pre>
|
||||
|
||||
<h2 id="deleting-in-place">Deleting in-place<a class="headerlink" href="#deleting-in-place" title="Permanent link">¶</a></h2>
|
||||
<pre><code class="bash">yq d -i sample.yaml b.c
|
||||
</code></pre>
|
||||
|
||||
<p>will update the sample.yaml file so that the 'c' node is deleted</p>
|
||||
<h3 id="multiple-documents-delete-from-single-document">Multiple Documents - delete from single document<a class="headerlink" href="#multiple-documents-delete-from-single-document" title="Permanent link">¶</a></h3>
|
||||
<h2 id="multiple-documents">Multiple Documents<a class="headerlink" href="#multiple-documents" title="Permanent link">¶</a></h2>
|
||||
<h3 id="delete-from-single-document">Delete from single document<a class="headerlink" href="#delete-from-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
field: leaveMe
|
||||
@ -497,7 +559,7 @@ b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-delete-from-all-documents">Multiple Documents - delete from all documents<a class="headerlink" href="#multiple-documents-delete-from-all-documents" title="Permanent link">¶</a></h3>
|
||||
<h3 id="delete-from-all-documents">Delete from all documents<a class="headerlink" href="#delete-from-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
field: deleteMe
|
||||
@ -517,8 +579,6 @@ field: deleteMeToo
|
||||
b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>Note that '*' is in quotes to avoid being interpreted by your shell.</p>
|
||||
|
||||
|
||||
|
||||
|
@ -279,8 +279,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
<a href="path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -291,8 +291,20 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
<a href="value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -459,13 +471,13 @@ sudo apt install yq -y
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
|
||||
<a href="read/" title="Read" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<a href="path_expressions/" title="Path Expressions" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Read
|
||||
Path Expressions
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
@ -94,7 +94,7 @@
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#to-stdout" tabindex="1" class="md-skip">
|
||||
<a href="#merge-example" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
@ -241,8 +241,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -253,8 +253,20 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -348,8 +360,8 @@
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
<a href="#merge-example" title="Merge example" class="md-nav__link">
|
||||
Merge example
|
||||
</a>
|
||||
|
||||
</li>
|
||||
@ -366,13 +378,19 @@
|
||||
Overwrite values
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#overwrite-values-with-arrays" title="Overwrite values with arrays" class="md-nav__link">
|
||||
Overwrite values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -383,18 +401,31 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-merge-into-single-document" title="Multiple Documents - merge into single document" class="md-nav__link">
|
||||
Multiple Documents - merge into single document
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#merge-into-single-document" title="Merge into single document" class="md-nav__link">
|
||||
Merge into single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-merge-into-all-documents" title="Multiple Documents - merge into all documents" class="md-nav__link">
|
||||
Multiple Documents - merge into all documents
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#merge-into-all-documents" title="Merge into all documents" class="md-nav__link">
|
||||
Merge into all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
@ -426,8 +457,8 @@
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
<a href="#merge-example" title="Merge example" class="md-nav__link">
|
||||
Merge example
|
||||
</a>
|
||||
|
||||
</li>
|
||||
@ -444,13 +475,19 @@
|
||||
Overwrite values
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#overwrite-values-with-arrays" title="Overwrite values with arrays" class="md-nav__link">
|
||||
Overwrite values with arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -461,18 +498,31 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-merge-into-single-document" title="Multiple Documents - merge into single document" class="md-nav__link">
|
||||
Multiple Documents - merge into single document
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#merge-into-single-document" title="Merge into single document" class="md-nav__link">
|
||||
Merge into single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-merge-into-all-documents" title="Multiple Documents - merge into all documents" class="md-nav__link">
|
||||
Multiple Documents - merge into all documents
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#merge-into-all-documents" title="Merge into all documents" class="md-nav__link">
|
||||
Merge into all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
@ -500,7 +550,7 @@ set values for any key not existing already or where the key has no value.</p>
|
||||
<pre><code>yq m <yaml_file> <path>...
|
||||
</code></pre>
|
||||
|
||||
<h3 id="to-stdout">To Stdout<a class="headerlink" href="#to-stdout" title="Permanent link">¶</a></h3>
|
||||
<h2 id="merge-example">Merge example<a class="headerlink" href="#merge-example" title="Permanent link">¶</a></h2>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
@ -523,24 +573,12 @@ c:
|
||||
test: 1
|
||||
</code></pre>
|
||||
|
||||
<h3 id="updating-files-in-place">Updating files in-place<a class="headerlink" href="#updating-files-in-place" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>and data2.yaml file of:</p>
|
||||
<pre><code class="yaml">a: other
|
||||
c:
|
||||
test: 1
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<h2 id="updating-files-in-place">Updating files in-place<a class="headerlink" href="#updating-files-in-place" title="Permanent link">¶</a></h2>
|
||||
<pre><code class="bash">yq m -i data1.yaml data2.yaml
|
||||
</code></pre>
|
||||
|
||||
<p>will update the data1.yaml file so that the value of 'c' is 'test: 1'.</p>
|
||||
<h3 id="overwrite-values">Overwrite values<a class="headerlink" href="#overwrite-values" title="Permanent link">¶</a></h3>
|
||||
<p>will update the data1.yaml file with the merged result.</p>
|
||||
<h2 id="overwrite-values">Overwrite values<a class="headerlink" href="#overwrite-values" title="Permanent link">¶</a></h2>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
@ -591,7 +629,7 @@ d: false
|
||||
</code></pre>
|
||||
|
||||
<p>Notice that 'b' does not result in the merging of the values within an array. </p>
|
||||
<h3 id="append-values-with-arrays">Append values with arrays<a class="headerlink" href="#append-values-with-arrays" title="Permanent link">¶</a></h3>
|
||||
<h2 id="append-values-with-arrays">Append values with arrays<a class="headerlink" href="#append-values-with-arrays" title="Permanent link">¶</a></h2>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
@ -620,7 +658,8 @@ d: hi
|
||||
</code></pre>
|
||||
|
||||
<p>Note that the 'b' array has concatenated the values from the second data file. Also note that other map keys are not overridden (field a).</p>
|
||||
<h3 id="multiple-documents-merge-into-single-document">Multiple Documents - merge into single document<a class="headerlink" href="#multiple-documents-merge-into-single-document" title="Permanent link">¶</a></h3>
|
||||
<h2 id="multiple-documents">Multiple Documents<a class="headerlink" href="#multiple-documents" title="Permanent link">¶</a></h2>
|
||||
<h3 id="merge-into-single-document">Merge into single document<a class="headerlink" href="#merge-into-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Currently yq only has multi-document support for the <em>first</em> document being merged into. The remaining yaml files will have their first document selected.</p>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
@ -644,7 +683,7 @@ a: simple
|
||||
b: dog
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-merge-into-all-documents">Multiple Documents - merge into all documents<a class="headerlink" href="#multiple-documents-merge-into-all-documents" title="Permanent link">¶</a></h3>
|
||||
<h3 id="merge-into-all-documents">Merge into all documents<a class="headerlink" href="#merge-into-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Currently yq only has multi-document support for the <em>first</em> document being merged into. The remaining yaml files will have their first document selected.</p>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
|
@ -239,18 +239,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -328,6 +316,19 @@
|
||||
Maps
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix splat" class="md-nav__link">
|
||||
Prefix splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -350,8 +351,8 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#finding-parents-with-particular-children-nodes" title="Finding parents with particular children nodes" class="md-nav__link">
|
||||
Finding parents with particular children nodes
|
||||
<a href="#search-by-children-nodes" title="Search by children nodes" class="md-nav__link">
|
||||
Search by children nodes
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
@ -412,6 +413,30 @@
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
@ -550,6 +575,19 @@
|
||||
Maps
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix splat" class="md-nav__link">
|
||||
Prefix splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -572,8 +610,8 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#finding-parents-with-particular-children-nodes" title="Finding parents with particular children nodes" class="md-nav__link">
|
||||
Finding parents with particular children nodes
|
||||
<a href="#search-by-children-nodes" title="Search by children nodes" class="md-nav__link">
|
||||
Search by children nodes
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
@ -640,7 +678,7 @@
|
||||
<h1>Path Expressions</h1>
|
||||
|
||||
<p>Path expressions are used to deeply navigate and match particular yaml nodes.</p>
|
||||
<p><em>As a general rule, you should wrap paths in quotes in the CLI to prevent your interpreter from processing '*, []' and other special characters.</em></p>
|
||||
<p><em>As a general rule, you should wrap paths in quotes to prevent your CLI from processing '*, []' and other special characters.</em></p>
|
||||
<h2 id="simple-expressions">Simple expressions<a class="headerlink" href="#simple-expressions" title="Permanent link">¶</a></h2>
|
||||
<h3 id="maps">Maps<a class="headerlink" href="#maps" title="Permanent link">¶</a></h3>
|
||||
<p>a.b.c</p>
|
||||
@ -679,8 +717,25 @@
|
||||
<pre><code class="yaml">a:
|
||||
b1:
|
||||
c: thing # MATCHES
|
||||
d: whatever
|
||||
b2:
|
||||
c: thing # MATCHES
|
||||
f: something irrelevant
|
||||
</code></pre>
|
||||
|
||||
<h4 id="prefix-splat">Prefix splat<a class="headerlink" href="#prefix-splat" title="Permanent link">¶</a></h4>
|
||||
<p>bob.item*.cats</p>
|
||||
<pre><code class="yaml">bob:
|
||||
item:
|
||||
cats: bananas # MATCHES
|
||||
something:
|
||||
cats: lemons
|
||||
itemThing:
|
||||
cats: more bananas # MATCHES
|
||||
item2:
|
||||
cats: apples # MATCHES
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<h3 id="arrays_1">Arrays<a class="headerlink" href="#arrays_1" title="Permanent link">¶</a></h3>
|
||||
@ -688,8 +743,11 @@
|
||||
<pre><code class="yaml">a:
|
||||
b:
|
||||
- c: thing0 # MATCHES
|
||||
d: what..ever
|
||||
- c: thing1 # MATCHES
|
||||
d: blarh
|
||||
- c: thing2 # MATCHES
|
||||
f: thingamabob
|
||||
</code></pre>
|
||||
|
||||
<h2 id="deep-splat">Deep Splat<a class="headerlink" href="#deep-splat" title="Permanent link">¶</a></h2>
|
||||
@ -698,18 +756,23 @@
|
||||
<pre><code class="yaml">a:
|
||||
b1:
|
||||
c: thing1 # MATCHES
|
||||
d: cat cat
|
||||
b2:
|
||||
c: thing2 # MATCHES
|
||||
d: dog dog
|
||||
b3:
|
||||
d:
|
||||
- f:
|
||||
c: thing3 # MATCHES
|
||||
d: beep
|
||||
- f:
|
||||
g:
|
||||
c: thing4 # MATCHES
|
||||
d: boop
|
||||
- d: mooo
|
||||
</code></pre>
|
||||
|
||||
<h2 id="finding-parents-with-particular-children-nodes">Finding parents with particular children nodes<a class="headerlink" href="#finding-parents-with-particular-children-nodes" title="Permanent link">¶</a></h2>
|
||||
<h2 id="search-by-children-nodes">Search by children nodes<a class="headerlink" href="#search-by-children-nodes" title="Permanent link">¶</a></h2>
|
||||
<p>a.(b.d==cat).b.c</p>
|
||||
<pre><code class="yaml">a:
|
||||
- b:
|
||||
@ -767,9 +830,8 @@
|
||||
<p>Any valid yaml key can be specified as part of a key lookup.</p>
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="keys-and-values-with-leading-dashes">Keys (and values) with leading dashes<a class="headerlink" href="#keys-and-values-with-leading-dashes" title="Permanent link">¶</a></h3>
|
||||
<p>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).</p>
|
||||
<p>To fix that, you will need to tell it to stop processing flags by adding '--' after the last flag like so:</p>
|
||||
<pre><code class="bash">yq n -t -- --key --value
|
||||
<p>The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags, if they start if a dash.</p>
|
||||
<pre><code class="bash">yq n -j -- --key --value
|
||||
</code></pre>
|
||||
|
||||
<p>Will result in</p>
|
||||
@ -795,7 +857,7 @@
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href="../read/" title="Read" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<a href=".." title="Install" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
@ -804,19 +866,19 @@
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Read
|
||||
Install
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../write/" title="Write/Update" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Write/Update
|
||||
Value Parsing
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
@ -94,7 +94,7 @@
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#to-stdout" tabindex="1" class="md-skip">
|
||||
<a href="#prefix-a-document" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
@ -241,8 +241,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -253,8 +253,20 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -300,15 +312,8 @@
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#arbitrary-depth" title="Arbitrary depth" class="md-nav__link">
|
||||
Arbitrary depth
|
||||
<a href="#prefix-a-document" title="Prefix a document" class="md-nav__link">
|
||||
Prefix a document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
@ -321,18 +326,31 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-prefix-a-single-document" title="Multiple Documents - prefix a single document" class="md-nav__link">
|
||||
Multiple Documents - prefix a single document
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-a-single-document" title="Prefix a single document" class="md-nav__link">
|
||||
Prefix a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-prefix-all-documents" title="Multiple Documents - prefix all documents" class="md-nav__link">
|
||||
Multiple Documents - prefix all documents
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-all-documents" title="Prefix all documents" class="md-nav__link">
|
||||
Prefix all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
@ -412,15 +430,8 @@
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#arbitrary-depth" title="Arbitrary depth" class="md-nav__link">
|
||||
Arbitrary depth
|
||||
<a href="#prefix-a-document" title="Prefix a document" class="md-nav__link">
|
||||
Prefix a document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
@ -433,18 +444,31 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-prefix-a-single-document" title="Multiple Documents - prefix a single document" class="md-nav__link">
|
||||
Multiple Documents - prefix a single document
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-a-single-document" title="Prefix a single document" class="md-nav__link">
|
||||
Prefix a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-prefix-all-documents" title="Multiple Documents - prefix all documents" class="md-nav__link">
|
||||
Multiple Documents - prefix all documents
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-all-documents" title="Prefix all documents" class="md-nav__link">
|
||||
Prefix all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
@ -472,23 +496,7 @@
|
||||
|
||||
<p>Prefixes a yaml document with the given path expression. The complete yaml content will be nested inside the new prefix path.</p>
|
||||
<p>See docs for <a href="../path_expressions/">path expression</a> for more details.</p>
|
||||
<h3 id="to-stdout">To Stdout<a class="headerlink" href="#to-stdout" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq p data1.yaml c
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">c:
|
||||
a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<h3 id="arbitrary-depth">Arbitrary depth<a class="headerlink" href="#arbitrary-depth" title="Permanent link">¶</a></h3>
|
||||
<h2 id="prefix-a-document">Prefix a document<a class="headerlink" href="#prefix-a-document" title="Permanent link">¶</a></h2>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a:
|
||||
b: [1, 2]
|
||||
@ -505,18 +513,13 @@ b: [1, 2]
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<h3 id="updating-files-in-place">Updating files in-place<a class="headerlink" href="#updating-files-in-place" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">a: simple
|
||||
b: [1, 2]
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<h2 id="updating-files-in-place">Updating files in-place<a class="headerlink" href="#updating-files-in-place" title="Permanent link">¶</a></h2>
|
||||
<pre><code class="bash">yq p -i data1.yaml c
|
||||
</code></pre>
|
||||
|
||||
<p>will update the data1.yaml file so that the path 'c' is prefixed to all other paths.</p>
|
||||
<h3 id="multiple-documents-prefix-a-single-document">Multiple Documents - prefix a single document<a class="headerlink" href="#multiple-documents-prefix-a-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>will update the data1.yaml file so that the path 'c' prefixes the document.</p>
|
||||
<h2 id="multiple-documents">Multiple Documents<a class="headerlink" href="#multiple-documents" title="Permanent link">¶</a></h2>
|
||||
<h3 id="prefix-a-single-document">Prefix a single document<a class="headerlink" href="#prefix-a-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
@ -536,7 +539,7 @@ c:
|
||||
b: cat
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-prefix-all-documents">Multiple Documents - prefix all documents<a class="headerlink" href="#multiple-documents-prefix-all-documents" title="Permanent link">¶</a></h3>
|
||||
<h3 id="prefix-all-documents">Prefix all documents<a class="headerlink" href="#prefix-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Given a data1.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
|
@ -239,6 +239,30 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -278,44 +302,29 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#reading-from-a-single-document" title="Reading from a single document" class="md-nav__link">
|
||||
Reading from a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#read-from-all-documents" title="Read from all documents" class="md-nav__link">
|
||||
Read from all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-specify-a-single-document" title="Multiple Documents - specify a single document" class="md-nav__link">
|
||||
Multiple Documents - specify a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-read-all-documents" title="Multiple Documents - read all documents" class="md-nav__link">
|
||||
Multiple Documents - read all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#arrays" title="Arrays" class="md-nav__link">
|
||||
Arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
@ -335,18 +344,6 @@
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
@ -447,44 +444,29 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#reading-from-a-single-document" title="Reading from a single document" class="md-nav__link">
|
||||
Reading from a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#read-from-all-documents" title="Read from all documents" class="md-nav__link">
|
||||
Read from all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-specify-a-single-document" title="Multiple Documents - specify a single document" class="md-nav__link">
|
||||
Multiple Documents - specify a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-read-all-documents" title="Multiple Documents - read all documents" class="md-nav__link">
|
||||
Multiple Documents - read all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#arrays" title="Arrays" class="md-nav__link">
|
||||
Arrays
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
@ -512,9 +494,10 @@
|
||||
<pre><code>yq r <yaml_file|json_file> <path_expression>
|
||||
</code></pre>
|
||||
|
||||
<p>TALK PRINTING ABOUT KEYS AND VALUES</p>
|
||||
<p>Returns the matching nodes of the path expression for the given yaml file (or STDIN).</p>
|
||||
<p>See docs for <a href="../path_expressions/">path expression</a> for more details.</p>
|
||||
<h3 id="basic">Basic<a class="headerlink" href="#basic" title="Permanent link">¶</a></h3>
|
||||
<h2 id="basic">Basic<a class="headerlink" href="#basic" title="Permanent link">¶</a></h2>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
@ -525,56 +508,14 @@
|
||||
</code></pre>
|
||||
|
||||
<p>will output the value of '2'.</p>
|
||||
<h3 id="from-stdin">From Stdin<a class="headerlink" href="#from-stdin" title="Permanent link">¶</a></h3>
|
||||
<h2 id="from-stdin">From Stdin<a class="headerlink" href="#from-stdin" title="Permanent link">¶</a></h2>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="bash">cat sample.yaml | yq r - b.c
|
||||
</code></pre>
|
||||
|
||||
<p>will output the value of '2'.</p>
|
||||
<h3 id="splat">Splat<a class="headerlink" href="#splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq r sample.yaml bob.*.cats
|
||||
</code></pre>
|
||||
|
||||
<p>will output</p>
|
||||
<pre><code class="yaml">- bananas
|
||||
- apples
|
||||
- oranges
|
||||
</code></pre>
|
||||
|
||||
<h3 id="prefix-splat">Prefix Splat<a class="headerlink" href="#prefix-splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq r sample.yaml bob.item*.cats
|
||||
</code></pre>
|
||||
|
||||
<p>will output</p>
|
||||
<pre><code class="yaml">- bananas
|
||||
- apples
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-specify-a-single-document">Multiple Documents - specify a single document<a class="headerlink" href="#multiple-documents-specify-a-single-document" title="Permanent link">¶</a></h3>
|
||||
<h2 id="multiple-documents">Multiple Documents<a class="headerlink" href="#multiple-documents" title="Permanent link">¶</a></h2>
|
||||
<h3 id="reading-from-a-single-document">Reading from a single document<a class="headerlink" href="#reading-from-a-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
@ -587,7 +528,7 @@ b:
|
||||
</code></pre>
|
||||
|
||||
<p>will output the value of '2'.</p>
|
||||
<h3 id="multiple-documents-read-all-documents">Multiple Documents - read all documents<a class="headerlink" href="#multiple-documents-read-all-documents" title="Permanent link">¶</a></h3>
|
||||
<h3 id="read-from-all-documents">Read from all documents<a class="headerlink" href="#read-from-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Reading all documents will return the result as an array. This can be converted to json using the '-j' flag if desired.</p>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">name: Fred
|
||||
@ -609,44 +550,6 @@ age: 232
|
||||
- Stella
|
||||
- Android
|
||||
</code></pre>
|
||||
|
||||
<h3 id="arrays">Arrays<a class="headerlink" href="#arrays" title="Permanent link">¶</a></h3>
|
||||
<p>You can give an index to access a specific element:
|
||||
e.g.: given a sample file of</p>
|
||||
<pre><code class="yaml">b:
|
||||
e:
|
||||
- name: fred
|
||||
value: 3
|
||||
- name: sam
|
||||
value: 4
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code>yq r sample.yaml 'b.e[1].name'
|
||||
</code></pre>
|
||||
|
||||
<p>will output 'sam'</p>
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="array-splat">Array Splat<a class="headerlink" href="#array-splat" title="Permanent link">¶</a></h3>
|
||||
<p>e.g.: given a sample file of</p>
|
||||
<pre><code class="yaml">b:
|
||||
e:
|
||||
- name: fred
|
||||
value: 3
|
||||
- name: sam
|
||||
value: 4
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code>yq r sample.yaml 'b.e[*].name'
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code>- fred
|
||||
- sam
|
||||
</code></pre>
|
||||
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
|
||||
|
||||
|
||||
@ -667,7 +570,7 @@ e.g.: given a sample file of</p>
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href=".." title="Install" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
@ -676,19 +579,19 @@ e.g.: given a sample file of</p>
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Install
|
||||
Value Parsing
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<a href="../write/" title="Write/Update" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Path Expressions
|
||||
Write/Update
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
File diff suppressed because one or more lines are too long
@ -2,47 +2,52 @@
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-13</lastmod>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-13</lastmod>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-13</lastmod>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-13</lastmod>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-13</lastmod>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-13</lastmod>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-13</lastmod>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-13</lastmod>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-13</lastmod>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
<url>
|
||||
<loc>None</loc>
|
||||
<lastmod>2020-01-17</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
Binary file not shown.
759
docs/value_parsing/index.html
Normal file
759
docs/value_parsing/index.html
Normal file
@ -0,0 +1,759 @@
|
||||
|
||||
|
||||
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" class="no-js">
|
||||
<head>
|
||||
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
|
||||
|
||||
|
||||
|
||||
<meta name="lang:clipboard.copy" content="Copy to clipboard">
|
||||
|
||||
<meta name="lang:clipboard.copied" content="Copied to clipboard">
|
||||
|
||||
<meta name="lang:search.language" content="en">
|
||||
|
||||
<meta name="lang:search.pipeline.stopwords" content="True">
|
||||
|
||||
<meta name="lang:search.pipeline.trimmer" content="True">
|
||||
|
||||
<meta name="lang:search.result.none" content="No matching documents">
|
||||
|
||||
<meta name="lang:search.result.one" content="1 matching document">
|
||||
|
||||
<meta name="lang:search.result.other" content="# matching documents">
|
||||
|
||||
<meta name="lang:search.tokenizer" content="[\s\-]+">
|
||||
|
||||
<link rel="shortcut icon" href="../assets/images/favicon.png">
|
||||
<meta name="generator" content="mkdocs-1.0.4, mkdocs-material-4.2.0">
|
||||
|
||||
|
||||
|
||||
<title>Value Parsing - Yq</title>
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/stylesheets/application.750b69bd.css">
|
||||
|
||||
|
||||
|
||||
|
||||
<script src="../assets/javascripts/modernizr.74668098.js"></script>
|
||||
|
||||
|
||||
|
||||
<link href="https://fonts.gstatic.com" rel="preconnect" crossorigin>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700|Roboto+Mono">
|
||||
<style>body,input{font-family:"Roboto","Helvetica Neue",Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono","Courier New",Courier,monospace}</style>
|
||||
|
||||
|
||||
<link rel="stylesheet" href="../assets/fonts/material-icons.css">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</head>
|
||||
|
||||
<body dir="ltr">
|
||||
|
||||
<svg class="md-svg">
|
||||
<defs>
|
||||
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="416" height="448"
|
||||
viewBox="0 0 416 448" id="__github">
|
||||
<path fill="currentColor" d="M160 304q0 10-3.125 20.5t-10.75 19-18.125
|
||||
8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19 18.125-8.5
|
||||
18.125 8.5 10.75 19 3.125 20.5zM320 304q0 10-3.125 20.5t-10.75
|
||||
19-18.125 8.5-18.125-8.5-10.75-19-3.125-20.5 3.125-20.5 10.75-19
|
||||
18.125-8.5 18.125 8.5 10.75 19 3.125 20.5zM360
|
||||
304q0-30-17.25-51t-46.75-21q-10.25 0-48.75 5.25-17.75 2.75-39.25
|
||||
2.75t-39.25-2.75q-38-5.25-48.75-5.25-29.5 0-46.75 21t-17.25 51q0 22 8
|
||||
38.375t20.25 25.75 30.5 15 35 7.375 37.25 1.75h42q20.5 0
|
||||
37.25-1.75t35-7.375 30.5-15 20.25-25.75 8-38.375zM416 260q0 51.75-15.25
|
||||
82.75-9.5 19.25-26.375 33.25t-35.25 21.5-42.5 11.875-42.875 5.5-41.75
|
||||
1.125q-19.5 0-35.5-0.75t-36.875-3.125-38.125-7.5-34.25-12.875-30.25-20.25-21.5-28.75q-15.5-30.75-15.5-82.75
|
||||
0-59.25 34-99-6.75-20.5-6.75-42.5 0-29 12.75-54.5 27 0 47.5 9.875t47.25
|
||||
30.875q36.75-8.75 77.25-8.75 37 0 70 8 26.25-20.5
|
||||
46.75-30.25t47.25-9.75q12.75 25.5 12.75 54.5 0 21.75-6.75 42 34 40 34
|
||||
99.5z" />
|
||||
</svg>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#default-behaviour" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
|
||||
<header class="md-header" data-md-component="header">
|
||||
<nav class="md-header-nav md-grid">
|
||||
<div class="md-flex">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<a href=".." title="Yq" class="md-header-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<label class="md-icon md-icon--menu md-header-nav__button" for="__drawer"></label>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch">
|
||||
<div class="md-flex__ellipsis md-header-nav__title" data-md-component="title">
|
||||
|
||||
<span class="md-header-nav__topic">
|
||||
Yq
|
||||
</span>
|
||||
<span class="md-header-nav__topic">
|
||||
Value Parsing
|
||||
</span>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
|
||||
<label class="md-icon md-icon--search md-header-nav__button" for="__search"></label>
|
||||
|
||||
<div class="md-search" data-md-component="search" role="dialog">
|
||||
<label class="md-search__overlay" for="__search"></label>
|
||||
<div class="md-search__inner" role="search">
|
||||
<form class="md-search__form" name="search">
|
||||
<input type="text" class="md-search__input" name="query" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="query" data-md-state="active">
|
||||
<label class="md-icon md-search__icon" for="__search"></label>
|
||||
<button type="reset" class="md-icon md-search__icon" data-md-component="reset" tabindex="-1">
|
||||

|
||||
</button>
|
||||
</form>
|
||||
<div class="md-search__output">
|
||||
<div class="md-search__scrollwrap" data-md-scrollfix>
|
||||
<div class="md-search-result" data-md-component="result">
|
||||
<div class="md-search-result__meta">
|
||||
Type to start searching
|
||||
</div>
|
||||
<ol class="md-search-result__list"></ol>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<div class="md-header-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<div class="md-container">
|
||||
|
||||
|
||||
|
||||
|
||||
<main class="md-main">
|
||||
<div class="md-main__inner md-grid" data-md-component="container">
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
<nav class="md-nav md-nav--primary" data-md-level="0">
|
||||
<label class="md-nav__title md-nav__title--site" for="__drawer">
|
||||
<a href=".." title="Yq" class="md-nav__button md-logo">
|
||||
|
||||
<i class="md-icon"></i>
|
||||
|
||||
</a>
|
||||
Yq
|
||||
</label>
|
||||
|
||||
<div class="md-nav__source">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/" title="Go to repository" class="md-source" data-md-source="github">
|
||||
|
||||
<div class="md-source__icon">
|
||||
<svg viewBox="0 0 24 24" width="24" height="24">
|
||||
<use xlink:href="#__github" width="24" height="24"></use>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div class="md-source__repository">
|
||||
mikefarah/yq
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href=".." title="Install" class="md-nav__link">
|
||||
Install
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item md-nav__item--active">
|
||||
|
||||
<input class="md-toggle md-nav__toggle" data-md-toggle="toc" type="checkbox" id="__toc">
|
||||
|
||||
|
||||
<label class="md-nav__link md-nav__link--active" for="__toc">
|
||||
Value Parsing
|
||||
</label>
|
||||
|
||||
<a href="./" title="Value Parsing" class="md-nav__link md-nav__link--active">
|
||||
Value Parsing
|
||||
</a>
|
||||
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#default-behaviour" title="Default behaviour" class="md-nav__link">
|
||||
Default behaviour
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#integers" title="Integers" class="md-nav__link">
|
||||
Integers
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#float" title="Float" class="md-nav__link">
|
||||
Float
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#booleans" title="Booleans" class="md-nav__link">
|
||||
Booleans
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#nulls" title="Nulls" class="md-nav__link">
|
||||
Nulls
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#strings" title="Strings" class="md-nav__link">
|
||||
Strings
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#using-the-tag-field-to-override" title="Using the tag field to override" class="md-nav__link">
|
||||
Using the tag field to override
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#casting-booleans" title="Casting booleans" class="md-nav__link">
|
||||
Casting booleans
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#casting-nulls" title="Casting nulls" class="md-nav__link">
|
||||
Casting nulls
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#custom-types" title="Custom types" class="md-nav__link">
|
||||
Custom types
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../write/" title="Write/Update" class="md-nav__link">
|
||||
Write/Update
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../prefix/" title="Prefix" class="md-nav__link">
|
||||
Prefix
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../delete/" title="Delete" class="md-nav__link">
|
||||
Delete
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../create/" title="Create" class="md-nav__link">
|
||||
Create
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../convert/" title="Convert" class="md-nav__link">
|
||||
Convert
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../merge/" title="Merge" class="md-nav__link">
|
||||
Merge
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-sidebar md-sidebar--secondary" data-md-component="toc">
|
||||
<div class="md-sidebar__scrollwrap">
|
||||
<div class="md-sidebar__inner">
|
||||
|
||||
<nav class="md-nav md-nav--secondary">
|
||||
|
||||
|
||||
|
||||
<label class="md-nav__title" for="__toc">Table of contents</label>
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#default-behaviour" title="Default behaviour" class="md-nav__link">
|
||||
Default behaviour
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#integers" title="Integers" class="md-nav__link">
|
||||
Integers
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#float" title="Float" class="md-nav__link">
|
||||
Float
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#booleans" title="Booleans" class="md-nav__link">
|
||||
Booleans
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#nulls" title="Nulls" class="md-nav__link">
|
||||
Nulls
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#strings" title="Strings" class="md-nav__link">
|
||||
Strings
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#using-the-tag-field-to-override" title="Using the tag field to override" class="md-nav__link">
|
||||
Using the tag field to override
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#casting-booleans" title="Casting booleans" class="md-nav__link">
|
||||
Casting booleans
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#casting-nulls" title="Casting nulls" class="md-nav__link">
|
||||
Casting nulls
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#custom-types" title="Custom types" class="md-nav__link">
|
||||
Custom types
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="md-content">
|
||||
<article class="md-content__inner md-typeset">
|
||||
|
||||
|
||||
<a href="https://github.com/mikefarah/yq/edit/master/docs/value_parsing.md" title="Edit this page" class="md-icon md-content__icon"></a>
|
||||
|
||||
|
||||
<h1>Value Parsing</h1>
|
||||
|
||||
<p>This describes how values are parsed from the CLI to commands that create/update yaml (e.g. new/write).</p>
|
||||
<p><code>yq</code> attempts to parse values intelligently, e.g. when a number is passed it - it will assume it's a number as opposed to a string. <code>yq</code> will not alter the representation of what you give. So if you pass '03.0' in, it will assume it's a number and keep the value formatted as it was passed in, that is '03.0'.</p>
|
||||
<p>The <code>--tag</code> flag can be used to override the tag type to force particular tags.</p>
|
||||
<h2 id="default-behaviour">Default behaviour<a class="headerlink" href="#default-behaviour" title="Permanent link">¶</a></h2>
|
||||
<h3 id="integers">Integers<a class="headerlink" href="#integers" title="Permanent link">¶</a></h3>
|
||||
<p><em>Given</em></p>
|
||||
<pre><code class="bash">yq new key 3
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: 3
|
||||
</code></pre>
|
||||
|
||||
<p><em>Given a formatted number</em></p>
|
||||
<pre><code class="bash">yq new key 03
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: 03
|
||||
</code></pre>
|
||||
|
||||
<p><code>yq</code> keeps the number formatted as it was passed in.</p>
|
||||
<h3 id="float">Float<a class="headerlink" href="#float" title="Permanent link">¶</a></h3>
|
||||
<p><em>Given</em></p>
|
||||
<pre><code class="bash">yq new key "3.1"
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: 3.1
|
||||
</code></pre>
|
||||
|
||||
<p>Note that quoting the number does not make a difference.</p>
|
||||
<p><em><em>Given a formatted decimal number</em></em></p>
|
||||
<pre><code class="bash">yq new key 03.0
|
||||
</code></pre>
|
||||
|
||||
<p>results in </p>
|
||||
<pre><code class="yaml">key: 03.0
|
||||
</code></pre>
|
||||
|
||||
<p><code>yq</code> will keep the number formatted as it was passed in</p>
|
||||
<h3 id="booleans">Booleans<a class="headerlink" href="#booleans" title="Permanent link">¶</a></h3>
|
||||
<pre><code class="bash">yq new key true
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: true
|
||||
</code></pre>
|
||||
|
||||
<h3 id="nulls">Nulls<a class="headerlink" href="#nulls" title="Permanent link">¶</a></h3>
|
||||
<pre><code class="bash">yq new key null
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: null
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yq new key '~'
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: ~
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yq new key ''
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key:
|
||||
</code></pre>
|
||||
|
||||
<h3 id="strings">Strings<a class="headerlink" href="#strings" title="Permanent link">¶</a></h3>
|
||||
<pre><code class="bash">yq new key whatever
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: whatever
|
||||
</code></pre>
|
||||
|
||||
<pre><code class="bash">yq new key ' whatever '
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: ' whatever '
|
||||
</code></pre>
|
||||
|
||||
<h2 id="using-the-tag-field-to-override">Using the tag field to override<a class="headerlink" href="#using-the-tag-field-to-override" title="Permanent link">¶</a></h2>
|
||||
<p>Previous versions of yq required double quoting to force values to be strings, this no longer works - instead use the --tag flag.</p>
|
||||
<h2 id="casting-booleans">Casting booleans<a class="headerlink" href="#casting-booleans" title="Permanent link">¶</a></h2>
|
||||
<pre><code class="bash">yq new --tag '!!str' key true
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: 'true'
|
||||
</code></pre>
|
||||
|
||||
<h2 id="casting-nulls">Casting nulls<a class="headerlink" href="#casting-nulls" title="Permanent link">¶</a></h2>
|
||||
<pre><code class="bash">yq new --tag '!!str' key null
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: 'null'
|
||||
</code></pre>
|
||||
|
||||
<h2 id="custom-types">Custom types<a class="headerlink" href="#custom-types" title="Permanent link">¶</a></h2>
|
||||
<pre><code class="bash">yq new --tag '!!farah' key gold
|
||||
</code></pre>
|
||||
|
||||
<p>results in</p>
|
||||
<pre><code class="yaml">key: !!farah gold
|
||||
</code></pre>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
<footer class="md-footer">
|
||||
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Path Expressions
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<a href="../read/" title="Read" class="md-flex md-footer-nav__link md-footer-nav__link--next" rel="next">
|
||||
<div class="md-flex__cell md-flex__cell--stretch md-footer-nav__title">
|
||||
<span class="md-flex__ellipsis">
|
||||
<span class="md-footer-nav__direction">
|
||||
Next
|
||||
</span>
|
||||
Read
|
||||
</span>
|
||||
</div>
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-forward md-footer-nav__button"></i>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-meta md-typeset">
|
||||
<div class="md-footer-meta__inner md-grid">
|
||||
<div class="md-footer-copyright">
|
||||
|
||||
powered by
|
||||
<a href="https://www.mkdocs.org">MkDocs</a>
|
||||
and
|
||||
<a href="https://squidfunk.github.io/mkdocs-material/">
|
||||
Material for MkDocs</a>
|
||||
</div>
|
||||
|
||||
<div class="md-footer-social">
|
||||
<link rel="stylesheet" href="../assets/fonts/font-awesome.css">
|
||||
|
||||
<a href="https://github.com/mikefarah" class="md-footer-social__link fa fa-github"></a>
|
||||
|
||||
<a href="https://www.linkedin.com/in/mike-farah-b5a75b2/" class="md-footer-social__link fa fa-linkedin"></a>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="../assets/javascripts/application.39abc4af.js"></script>
|
||||
|
||||
<script>app.initialize({version:"1.0.4",url:{base:".."}})</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -94,7 +94,7 @@
|
||||
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
|
||||
<label class="md-overlay" data-md-component="overlay" for="__drawer"></label>
|
||||
|
||||
<a href="#to-stdout" tabindex="1" class="md-skip">
|
||||
<a href="#basic" tabindex="1" class="md-skip">
|
||||
Skip to content
|
||||
</a>
|
||||
|
||||
@ -241,8 +241,8 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -253,8 +253,20 @@
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-nav__link">
|
||||
Path Expressions
|
||||
<a href="../value_parsing/" title="Value Parsing" class="md-nav__link">
|
||||
Value Parsing
|
||||
</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="../read/" title="Read" class="md-nav__link">
|
||||
Read
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@ -288,10 +300,23 @@
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
<a href="#basic" title="Basic" class="md-nav__link">
|
||||
Basic
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -306,27 +331,6 @@
|
||||
Adding new fields
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -337,23 +341,29 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-update-a-single-document" title="Multiple Documents - update a single document" class="md-nav__link">
|
||||
Multiple Documents - update a single document
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#update-a-single-document" title="Update a single document" class="md-nav__link">
|
||||
Update a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-update-all-documents" title="Multiple Documents - update all documents" class="md-nav__link">
|
||||
Multiple Documents - update all documents
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#update-all-documents" title="Update all documents" class="md-nav__link">
|
||||
Update all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
@ -364,13 +374,6 @@
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#values-starting-with-a-hyphen-or-dash" title="Values starting with a hyphen (or dash)" class="md-nav__link">
|
||||
Values starting with a hyphen (or dash)
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
@ -461,10 +464,23 @@
|
||||
<ul class="md-nav__list" data-md-scrollfix>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#to-stdout" title="To Stdout" class="md-nav__link">
|
||||
To Stdout
|
||||
<a href="#basic" title="Basic" class="md-nav__link">
|
||||
Basic
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -479,27 +495,6 @@
|
||||
Adding new fields
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#splat" title="Splat" class="md-nav__link">
|
||||
Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#prefix-splat" title="Prefix Splat" class="md-nav__link">
|
||||
Prefix Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#array-splat" title="Array Splat" class="md-nav__link">
|
||||
Array Splat
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
@ -510,23 +505,29 @@
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-update-a-single-document" title="Multiple Documents - update a single document" class="md-nav__link">
|
||||
Multiple Documents - update a single document
|
||||
<a href="#multiple-documents" title="Multiple Documents" class="md-nav__link">
|
||||
Multiple Documents
|
||||
</a>
|
||||
|
||||
<nav class="md-nav">
|
||||
<ul class="md-nav__list">
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#update-a-single-document" title="Update a single document" class="md-nav__link">
|
||||
Update a single document
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#multiple-documents-update-all-documents" title="Multiple Documents - update all documents" class="md-nav__link">
|
||||
Multiple Documents - update all documents
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#update-all-documents" title="Update all documents" class="md-nav__link">
|
||||
Update all documents
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#updating-files-in-place" title="Updating files in-place" class="md-nav__link">
|
||||
Updating files in-place
|
||||
</a>
|
||||
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
</li>
|
||||
|
||||
@ -537,13 +538,6 @@
|
||||
|
||||
</li>
|
||||
|
||||
<li class="md-nav__item">
|
||||
<a href="#values-starting-with-a-hyphen-or-dash" title="Values starting with a hyphen (or dash)" class="md-nav__link">
|
||||
Values starting with a hyphen (or dash)
|
||||
</a>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
@ -570,7 +564,7 @@
|
||||
|
||||
<p>Updates all the matching nodes of path expression to the supplied value.</p>
|
||||
<p>See docs for <a href="../path_expressions/">path expression</a> for more details.</p>
|
||||
<h3 id="to-stdout">To Stdout<a class="headerlink" href="#to-stdout" title="Permanent link">¶</a></h3>
|
||||
<h2 id="basic">Basic<a class="headerlink" href="#basic" title="Permanent link">¶</a></h2>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
@ -585,11 +579,16 @@
|
||||
c: cat
|
||||
</code></pre>
|
||||
|
||||
<h3 id="from-stdin">From STDIN<a class="headerlink" href="#from-stdin" title="Permanent link">¶</a></h3>
|
||||
<h3 id="updating-files-in-place">Updating files in-place<a class="headerlink" href="#updating-files-in-place" title="Permanent link">¶</a></h3>
|
||||
<pre><code class="bash">yq w -i sample.yaml b.c cat
|
||||
</code></pre>
|
||||
|
||||
<p>will update the sample.yaml file so that the value of 'c' is cat.</p>
|
||||
<h2 id="from-stdin">From STDIN<a class="headerlink" href="#from-stdin" title="Permanent link">¶</a></h2>
|
||||
<pre><code class="bash">cat sample.yaml | yq w - b.c blah
|
||||
</code></pre>
|
||||
|
||||
<h3 id="adding-new-fields">Adding new fields<a class="headerlink" href="#adding-new-fields" title="Permanent link">¶</a></h3>
|
||||
<h2 id="adding-new-fields">Adding new fields<a class="headerlink" href="#adding-new-fields" title="Permanent link">¶</a></h2>
|
||||
<p>Any missing fields in the path will be created on the fly.</p>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
@ -607,82 +606,7 @@
|
||||
- new thing
|
||||
</code></pre>
|
||||
|
||||
<h3 id="splat">Splat<a class="headerlink" href="#splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w sample.yaml bob.*.cats meow
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: meow
|
||||
item2:
|
||||
cats: meow
|
||||
thing:
|
||||
cats: meow
|
||||
</code></pre>
|
||||
|
||||
<h3 id="prefix-splat">Prefix Splat<a class="headerlink" href="#prefix-splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: bananas
|
||||
item2:
|
||||
cats: apples
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w sample.yaml bob.item*.cats meow
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
item1:
|
||||
cats: meow
|
||||
item2:
|
||||
cats: meow
|
||||
thing:
|
||||
cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<h3 id="array-splat">Array Splat<a class="headerlink" href="#array-splat" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
- cats: bananas
|
||||
- cats: apples
|
||||
- cats: oranges
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w sample.yaml bob[*].cats meow
|
||||
</code></pre>
|
||||
|
||||
<p>will output:</p>
|
||||
<pre><code class="yaml">---
|
||||
bob:
|
||||
- cats: meow
|
||||
- cats: meow
|
||||
- cats: meow
|
||||
</code></pre>
|
||||
|
||||
<h3 id="appending-value-to-an-array-field">Appending value to an array field<a class="headerlink" href="#appending-value-to-an-array-field" title="Permanent link">¶</a></h3>
|
||||
<h2 id="appending-value-to-an-array-field">Appending value to an array field<a class="headerlink" href="#appending-value-to-an-array-field" title="Permanent link">¶</a></h2>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
@ -705,7 +629,8 @@ bob:
|
||||
</code></pre>
|
||||
|
||||
<p>Note that the path is in quotes to avoid the square brackets being interpreted by your shell.</p>
|
||||
<h3 id="multiple-documents-update-a-single-document">Multiple Documents - update a single document<a class="headerlink" href="#multiple-documents-update-a-single-document" title="Permanent link">¶</a></h3>
|
||||
<h2 id="multiple-documents">Multiple Documents<a class="headerlink" href="#multiple-documents" title="Permanent link">¶</a></h2>
|
||||
<h3 id="update-a-single-document">Update a single document<a class="headerlink" href="#update-a-single-document" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
@ -724,7 +649,7 @@ b:
|
||||
c: 5
|
||||
</code></pre>
|
||||
|
||||
<h3 id="multiple-documents-update-all-documents">Multiple Documents - update all documents<a class="headerlink" href="#multiple-documents-update-all-documents" title="Permanent link">¶</a></h3>
|
||||
<h3 id="update-all-documents">Update all documents<a class="headerlink" href="#update-all-documents" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">something: else
|
||||
---
|
||||
@ -745,19 +670,10 @@ b:
|
||||
c: 5
|
||||
</code></pre>
|
||||
|
||||
<p>Note that '*' is in quotes to avoid being interpreted by your shell.</p>
|
||||
<h3 id="updating-files-in-place">Updating files in-place<a class="headerlink" href="#updating-files-in-place" title="Permanent link">¶</a></h3>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
</code></pre>
|
||||
|
||||
<p>then</p>
|
||||
<pre><code class="bash">yq w -i sample.yaml b.c cat
|
||||
</code></pre>
|
||||
|
||||
<p>will update the sample.yaml file so that the value of 'c' is cat.</p>
|
||||
<h3 id="updating-multiple-values-with-a-script">Updating multiple values with a script<a class="headerlink" href="#updating-multiple-values-with-a-script" title="Permanent link">¶</a></h3>
|
||||
<p>UPDATE THIS
|
||||
UPDATE THIS
|
||||
INCLUDE DELETE EXAMPLE</p>
|
||||
<h2 id="updating-multiple-values-with-a-script">Updating multiple values with a script<a class="headerlink" href="#updating-multiple-values-with-a-script" title="Permanent link">¶</a></h2>
|
||||
<p>Given a sample.yaml file of:</p>
|
||||
<pre><code class="yaml">b:
|
||||
c: 2
|
||||
@ -784,16 +700,6 @@ b.e[+].name: Howdy Partner
|
||||
<p>And, of course, you can pipe the instructions in using '-':</p>
|
||||
<pre><code class="bash">cat update_instructions.yaml | yq w -s - sample.yaml
|
||||
</code></pre>
|
||||
|
||||
<h3 id="values-starting-with-a-hyphen-or-dash">Values starting with a hyphen (or dash)<a class="headerlink" href="#values-starting-with-a-hyphen-or-dash" title="Permanent link">¶</a></h3>
|
||||
<p>The flag terminator needs to be used to stop the app from attempting to parse the subsequent arguments as flags:</p>
|
||||
<pre><code>yq w -- my.path -3
|
||||
</code></pre>
|
||||
|
||||
<p>will output</p>
|
||||
<pre><code class="yaml">my:
|
||||
path: -3
|
||||
</code></pre>
|
||||
|
||||
|
||||
|
||||
@ -814,7 +720,7 @@ b.e[+].name: Howdy Partner
|
||||
<div class="md-footer-nav">
|
||||
<nav class="md-footer-nav__inner md-grid">
|
||||
|
||||
<a href="../path_expressions/" title="Path Expressions" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<a href="../read/" title="Read" class="md-flex md-footer-nav__link md-footer-nav__link--prev" rel="prev">
|
||||
<div class="md-flex__cell md-flex__cell--shrink">
|
||||
<i class="md-icon md-icon--arrow-back md-footer-nav__button"></i>
|
||||
</div>
|
||||
@ -823,7 +729,7 @@ b.e[+].name: Howdy Partner
|
||||
<span class="md-footer-nav__direction">
|
||||
Previous
|
||||
</span>
|
||||
Path Expressions
|
||||
Read
|
||||
</span>
|
||||
</div>
|
||||
</a>
|
||||
|
@ -4,8 +4,9 @@ site_name: Yq
|
||||
theme: 'material'
|
||||
pages:
|
||||
- Install: index.md
|
||||
- Read: read.md
|
||||
- Path Expressions: path_expressions.md
|
||||
- Value Parsing: value_parsing.md
|
||||
- Read: read.md
|
||||
- Write/Update: write.md
|
||||
- Prefix: prefix.md
|
||||
- Delete: delete.md
|
||||
|
161
mkdocs/value_parsing.md
Normal file
161
mkdocs/value_parsing.md
Normal file
@ -0,0 +1,161 @@
|
||||
This describes how values are parsed from the CLI to commands that create/update yaml (e.g. new/write).
|
||||
|
||||
`yq` attempts to parse values intelligently, e.g. when a number is passed it - it will assume it's a number as opposed to a string. `yq` will not alter the representation of what you give. So if you pass '03.0' in, it will assume it's a number and keep the value formatted as it was passed in, that is '03.0'.
|
||||
|
||||
The `--tag` flag can be used to override the tag type to force particular tags.
|
||||
|
||||
|
||||
## Default behaviour
|
||||
|
||||
### Integers
|
||||
*Given*
|
||||
```bash
|
||||
yq new key 3
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: 3
|
||||
```
|
||||
|
||||
*Given a formatted number*
|
||||
|
||||
```bash
|
||||
yq new key 03
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: 03
|
||||
```
|
||||
`yq` keeps the number formatted as it was passed in.
|
||||
|
||||
### Float
|
||||
*Given*
|
||||
```bash
|
||||
yq new key "3.1"
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: 3.1
|
||||
```
|
||||
Note that quoting the number does not make a difference.
|
||||
|
||||
*Given a formatted decimal number*
|
||||
|
||||
```bash
|
||||
yq new key 03.0
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: 03.0
|
||||
```
|
||||
`yq` keeps the number formatted as it was passed in
|
||||
|
||||
### Booleans
|
||||
```bash
|
||||
yq new key true
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: true
|
||||
```
|
||||
|
||||
### Nulls
|
||||
```bash
|
||||
yq new key null
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: null
|
||||
```
|
||||
|
||||
```bash
|
||||
yq new key '~'
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: ~
|
||||
```
|
||||
|
||||
```bash
|
||||
yq new key ''
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key:
|
||||
```
|
||||
|
||||
### Strings
|
||||
```bash
|
||||
yq new key whatever
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: whatever
|
||||
```
|
||||
|
||||
```bash
|
||||
yq new key ' whatever '
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: ' whatever '
|
||||
```
|
||||
|
||||
## Using the tag field to override
|
||||
|
||||
Previous versions of yq required double quoting to force values to be strings, this no longer works - instead use the --tag flag.
|
||||
|
||||
|
||||
|
||||
## Casting booleans
|
||||
```bash
|
||||
yq new --tag '!!str' key true
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: 'true'
|
||||
```
|
||||
|
||||
## Casting nulls
|
||||
```bash
|
||||
yq new --tag '!!str' key null
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: 'null'
|
||||
```
|
||||
|
||||
## Custom types
|
||||
```bash
|
||||
yq new --tag '!!farah' key gold
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```yaml
|
||||
key: !!farah gold
|
||||
```
|
Loading…
Reference in New Issue
Block a user