Comments (20)
Thanks!
from dasel.
Are you referring to the JSON content within node.longhorn.io/default-disks-config
?
On another note, please use 3 backticks for code highlighting instead of 1. That way new lines etc are displayed properly.
from dasel.
Thanks, I would to create the complete data structure from scratch
from dasel.
You can use dasel put string
with a blank input to create new documents.
E.g.
echo '' | dasel put string -p yaml some.path.here value
some:
path:
here: value
You can then pipe that output into another dasel command:
echo '' | dasel put string -p yaml 'some.path.here' value | dasel put string -p yaml 'some.path.too' value2
some:
path:
here: value
too: value2
I just made a release that will allow you to use .
in the property name by escaping it. Download dasel v1.5.0
and then the following should work:
echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast", "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/create-default-disk' config
If you want to save this file just add > myfile.yaml
at the end of the command.
I've just ran this locally with v1.5.0
:
echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast", "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/create-default-disk' config
metadata:
annotations:
node.longhorn.io/create-default-disk: config
node.longhorn.io/default-disks-config: '[ { "name":"fast", "path":"/mnt/data-fast1",
"allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1",
"allowScheduling":true, "tags":["slow"]} ]'
from dasel.
Hi @TomWright,
Thanks, looking good. One question, this part:
" node.longhorn.io/default-disks-config: '[ { \"name\":\"fast\", \"path\":\"/mnt/data-fast1\", \"allowScheduling\":true, \"tags\":[\"fast\"]}, { \"name\":\"slow\", \"path\":\"/mnt/data-slow1\", \"allowScheduling\":true, \"tags\":[\"slow\"]} ]'" \
Is it possible to create this as an array? As far as I understand it, this part is an array and I do need 1 to x entries in this part, depending on the number of disks.
Thanks!
from dasel.
Just append []
to the selector you want to be an array.
https://github.com/TomWright/dasel#next-available-index
from dasel.
Hi @TomWright ,
Thanks, I really appreciate the help you are giving, could you give me an example how to create this with an array?
metadata:
annotations:
node.longhorn.io/create-default-disk: config
node.longhorn.io/default-disks-config: '[ { "name":"fast", "path":"/mnt/data-fast1",
"allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1",
"allowScheduling":true, "tags":["slow"]} ]'
The part of the disks-config is what I am looking for.
Thanks again
from dasel.
Those values are in a JSON string. Do you want them as JSON or as YAML?
from dasel.
Hi @TomWright ,
That should be JSON, thanks.
from dasel.
echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config.[]' '[ { "name":"fast", "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/create-default-disk' config
from dasel.
Hi @TomWright ,
Could you please take a look at this again?
I am trying to use your example, but it is different from my example. In your example config (last line) is also on metadata.annotation, but in my question it is on metadata.labels. When I replace the word annotation with labels it is not working, also not when I am splitting it into 2 commands.
This is not giving the line with the labels:
echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast", "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.labels.node\.longhorn\.io\/create-default-disk' config
Also splitting it into 2 parts doesn't work:
longhorn_disk_annotation=$(echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast", "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]')
result=$(echo "$longhorn_disk_annotation" | dasel put string -p yaml 'metadata.labels.node\.longhorn\.io\/create-default-disk' config)
How can I get this working?
from dasel.
What is the final output you want to see?
from dasel.
This :-)
metadata:
annotations:
node.longhorn.io/default-disks-config: '[ { "name":"fast", "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]'
labels:
node.longhorn.io/create-default-disk: config
from dasel.
Hello @TomWright,
I have tried it with variables and with files, the second put string is not working. Is this a bug or am I doing something wrong?
from dasel.
I'll take a look at this today and get back to you
from dasel.
Great, thanks!
from dasel.
Hey @ws-way, this looks like a bug.
I'm debugging it now and will release a fix ASAP. Thanks for your patience 👍
from dasel.
Ok, thanks, good luck with the fix
from dasel.
OK the issue is fixed as of v1.5.1
.
echo '' | dasel put string -p yaml 'metadata.annotations.node\.longhorn\.io\/default-disks-config' '[ { "name":"fast", "path":"/mnt/data-fast1", "allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1", "allowScheduling":true, "tags":["slow"]} ]' | dasel put string -p yaml 'metadata.labels.node\.longhorn\.io\/create-default-disk' 'config'
Output is:
metadata:
annotations:
node.longhorn.io/default-disks-config: '[ { "name":"fast", "path":"/mnt/data-fast1",
"allowScheduling":true, "tags":["fast"]}, { "name":"slow", "path":"/mnt/data-slow1",
"allowScheduling":true, "tags":["slow"]} ]'
labels:
node.longhorn.io/create-default-disk: config
from dasel.
Looks it is working, thanks again!
from dasel.
Related Issues (20)
- YAML: multiple documents in a single YAML file are not handled correctly HOT 2
- Dasel can't read arrays from yaml file without hyphen HOT 1
- The fields with null value just disappear in the output HOT 1
- Hex, binary and octal values are not parsed in yaml HOT 3
- Int instead of string added to a document HOT 4
- Manual Installation for Windows - Improvement HOT 4
- Converting JSON -> YAML -> JSON errors if timestamp fields are involved HOT 3
- Unable to select on CSVs without transforming to a different format HOT 3
- [REG 2.2->2.3] Superfluous quotes in selector output HOT 2
- Handle quotes in values HOT 2
- `dasel put --type string` not working when converting to yaml HOT 5
- Delete selector can't find keys with null values HOT 2
- Special characters inside string literals are replaced with Unicode escape sequences in JSON HOT 3
- contains/includes HOT 2
- -w xml is not working when -r is not xml HOT 3
- Support multiple files HOT 1
- CSV file format: Support other characters as separator HOT 2
- Output formatting is not right in some arrays HOT 6
- [BUG] Dasel crash when reading an empty file HOT 5
- Suppress header generation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dasel.