| 1 | package kdlscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.25 fmt/" |
| 5 | |
| 6 | "github.com/tomwright/dasel/v3/modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/" |
| 7 | "github.com/tomwright/dasel/v3/parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/" |
| 8 | "github.com/tomwright/dasel/v3/parsing/kdl/internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/" |
| 9 | ) |
| 10 | |
| 11 | var _ parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.Writerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Writer# = (*kdlWriterscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#)(nil) |
| 12 | |
| 13 | func newKDLWriterscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/newKDLWriter().(options parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.WriterOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/WriterOptions#) (parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.Writerscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/Writer#, error) { |
| 14 | return &kdlWriterscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#{optionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#options.: options}, nil |
| 15 | } |
| 16 | |
| 17 | type kdlWriterscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter# struct { |
| 18 | optionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#options. parsingscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/.WriterOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/WriterOptions# |
| 19 | } |
| 20 | |
| 21 | func (w *kdlWriterscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#) Writescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#Write().(value *modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) ([]byte, error) { |
| 22 | doc, err := modelValueToDocumentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelValueToDocument().(value) |
| 23 | if err != nil { |
| 24 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("kdl: %w", err) |
| 25 | } |
| 26 | |
| 27 | opts := internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.DefaultGenerateOptionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/DefaultGenerateOptions().() |
| 28 | opts.Compactscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateOptions#Compact. = w.optionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#options..Compactscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/WriterOptions#Compact. |
| 29 | if w.optionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#options..Indentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/WriterOptions#Indent. != "" { |
| 30 | opts.Indentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateOptions#Indent. = w.optionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#options..Indentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/WriterOptions#Indent. |
| 31 | } |
| 32 | if v, ok := w.optionsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/kdlWriter#options..Extscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing`/WriterOptions#Ext.["kdl-version"]; ok { |
| 33 | switch v { |
| 34 | case "1": |
| 35 | opts.Versionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateOptions#Version. = internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Version1scip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Version1. |
| 36 | case "2": |
| 37 | opts.Versionscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateOptions#Version. = internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Version2scip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Version2. |
| 38 | default: |
| 39 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("kdl: unsupported output version %q (use 1 or 2)", v) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | result, err := internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.GenerateStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/GenerateString().(doc, opts) |
| 44 | if err != nil { |
| 45 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("kdl: %w", err) |
| 46 | } |
| 47 | |
| 48 | return []byte(result), nil |
| 49 | } |
| 50 | |
| 51 | func modelValueToDocumentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelValueToDocument().(value *modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (*internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Documentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#, error) { |
| 52 | if value.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() != modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap. { |
| 53 | // Non-map root: wrap as a single node |
| 54 | node, err := modelValueToNodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelValueToNode().("root", value) |
| 55 | if err != nil { |
| 56 | return nil, err |
| 57 | } |
| 58 | return &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Documentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#{Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.: []*internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#{node}}, nil |
| 59 | } |
| 60 | |
| 61 | nodes, err := mapToNodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/mapToNodes().(value) |
| 62 | if err != nil { |
| 63 | return nil, err |
| 64 | } |
| 65 | return &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Documentscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#{Nodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Document#Nodes.: nodes}, nil |
| 66 | } |
| 67 | |
| 68 | func mapToNodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/mapToNodes().(value *modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) ([]*internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#, error) { |
| 69 | kvs, err := value.MapKeyValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeyValues().() |
| 70 | if err != nil { |
| 71 | return nil, err |
| 72 | } |
| 73 | |
| 74 | var nodes []*internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node# |
| 75 | for _, kv := range kvs { |
| 76 | if kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value..Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() == modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice. { |
| 77 | // Slice → duplicate nodes with the same name |
| 78 | sliceNodes, err := sliceToNodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/sliceToNodes().(kv.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Key., kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value.) |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | nodes = append(nodes, sliceNodes...) |
| 83 | } else { |
| 84 | node, err := modelValueToNodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelValueToNode().(kv.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Key., kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value.) |
| 85 | if err != nil { |
| 86 | return nil, err |
| 87 | } |
| 88 | nodes = append(nodes, node) |
| 89 | } |
| 90 | } |
| 91 | return nodes, nil |
| 92 | } |
| 93 | |
| 94 | func sliceToNodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/sliceToNodes().(name string, value *modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) ([]*internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#, error) { |
| 95 | length, err := value.SliceLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SliceLen().() |
| 96 | if err != nil { |
| 97 | return nil, err |
| 98 | } |
| 99 | |
| 100 | var nodes []*internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node# |
| 101 | for i := 0; i < length; i++ { |
| 102 | elem, err := value.GetSliceIndexscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetSliceIndex().(i) |
| 103 | if err != nil { |
| 104 | return nil, err |
| 105 | } |
| 106 | node, err := modelValueToNodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelValueToNode().(name, elem) |
| 107 | if err != nil { |
| 108 | return nil, err |
| 109 | } |
| 110 | nodes = append(nodes, node) |
| 111 | } |
| 112 | return nodes, nil |
| 113 | } |
| 114 | |
| 115 | func modelValueToNodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelValueToNode().(name string, value *modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (*internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#, error) { |
| 116 | node := &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#{Namescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Name.: name} |
| 117 | |
| 118 | switch value.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() { |
| 119 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeString.: |
| 120 | s, err := value.StringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringValue().() |
| 121 | if err != nil { |
| 122 | return nil, err |
| 123 | } |
| 124 | node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments. = append(node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments., &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.: s}) |
| 125 | |
| 126 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeInt.: |
| 127 | n, err := value.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().() |
| 128 | if err != nil { |
| 129 | return nil, err |
| 130 | } |
| 131 | node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments. = append(node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments., &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.: n}) |
| 132 | |
| 133 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeFloat.: |
| 134 | f, err := value.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().() |
| 135 | if err != nil { |
| 136 | return nil, err |
| 137 | } |
| 138 | node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments. = append(node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments., &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.: f}) |
| 139 | |
| 140 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeBoolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeBool.: |
| 141 | b, err := value.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().() |
| 142 | if err != nil { |
| 143 | return nil, err |
| 144 | } |
| 145 | node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments. = append(node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments., &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.: b}) |
| 146 | |
| 147 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeNull.: |
| 148 | // Node with no args/props/children represents null |
| 149 | |
| 150 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeMapscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeMap.: |
| 151 | // Check for $args key |
| 152 | kvs, err := value.MapKeyValuesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#MapKeyValues().() |
| 153 | if err != nil { |
| 154 | return nil, err |
| 155 | } |
| 156 | |
| 157 | var childNodes []*internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Nodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node# |
| 158 | for _, kv := range kvs { |
| 159 | if kv.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Key. == "$args" { |
| 160 | // $args → node arguments |
| 161 | if kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value..Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() == modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice. { |
| 162 | length, err := kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value..SliceLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SliceLen().() |
| 163 | if err != nil { |
| 164 | return nil, err |
| 165 | } |
| 166 | for i := 0; i < length; i++ { |
| 167 | elem, err := kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value..GetSliceIndexscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetSliceIndex().(i) |
| 168 | if err != nil { |
| 169 | return nil, err |
| 170 | } |
| 171 | kdlVal, err := modelToKDLValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelToKDLValue().(elem) |
| 172 | if err != nil { |
| 173 | return nil, err |
| 174 | } |
| 175 | node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments. = append(node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments., kdlVal) |
| 176 | } |
| 177 | } |
| 178 | continue |
| 179 | } |
| 180 | |
| 181 | // Scalar values → properties, complex values → children |
| 182 | if isScalarTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/isScalarType().(kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value..Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().()) { |
| 183 | kdlVal, err := modelToKDLValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelToKDLValue().(kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value.) |
| 184 | if err != nil { |
| 185 | return nil, err |
| 186 | } |
| 187 | node.Propertiesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Properties. = append(node.Propertiesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Properties., &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Propertyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#{ |
| 188 | Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Key.: kv.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Key., |
| 189 | Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Property#Value.: kdlVal, |
| 190 | }) |
| 191 | } else { |
| 192 | // Map or slice value → child nodes |
| 193 | if kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value..Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() == modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice. { |
| 194 | sliceNodes, err := sliceToNodesscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/sliceToNodes().(kv.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Key., kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value.) |
| 195 | if err != nil { |
| 196 | return nil, err |
| 197 | } |
| 198 | childNodes = append(childNodes, sliceNodes...) |
| 199 | } else { |
| 200 | childNode, err := modelValueToNodescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelValueToNode().(kv.Keyscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Key., kv.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/KeyValue#Value.) |
| 201 | if err != nil { |
| 202 | return nil, err |
| 203 | } |
| 204 | childNodes = append(childNodes, childNode) |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | if len(childNodes) > 0 { |
| 210 | node.Childrenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Children. = childNodes |
| 211 | } |
| 212 | |
| 213 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeSlicescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeSlice.: |
| 214 | // Slice as direct value → arguments |
| 215 | length, err := value.SliceLenscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#SliceLen().() |
| 216 | if err != nil { |
| 217 | return nil, err |
| 218 | } |
| 219 | for i := 0; i < length; i++ { |
| 220 | elem, err := value.GetSliceIndexscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#GetSliceIndex().(i) |
| 221 | if err != nil { |
| 222 | return nil, err |
| 223 | } |
| 224 | kdlVal, err := modelToKDLValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelToKDLValue().(elem) |
| 225 | if err != nil { |
| 226 | return nil, err |
| 227 | } |
| 228 | node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments. = append(node.Argumentsscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Node#Arguments., kdlVal) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | return node, nil |
| 233 | } |
| 234 | |
| 235 | func modelToKDLValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/modelToKDLValue().(value *modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#) (*internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#, error) { |
| 236 | switch value.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().() { |
| 237 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeString.: |
| 238 | s, err := value.StringValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#StringValue().() |
| 239 | if err != nil { |
| 240 | return nil, err |
| 241 | } |
| 242 | return &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.: s}, nil |
| 243 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeInt.: |
| 244 | n, err := value.IntValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#IntValue().() |
| 245 | if err != nil { |
| 246 | return nil, err |
| 247 | } |
| 248 | return &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.: n}, nil |
| 249 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeFloat.: |
| 250 | f, err := value.FloatValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#FloatValue().() |
| 251 | if err != nil { |
| 252 | return nil, err |
| 253 | } |
| 254 | return &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.: f}, nil |
| 255 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeBoolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeBool.: |
| 256 | b, err := value.BoolValuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#BoolValue().() |
| 257 | if err != nil { |
| 258 | return nil, err |
| 259 | } |
| 260 | return &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.: b}, nil |
| 261 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeNull.: |
| 262 | return &internalscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/.Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#{Valuescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl/internal`/Value#Value.: nil}, nil |
| 263 | default: |
| 264 | return nil, fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("cannot convert %s to KDL value", value.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Value#Type().()) |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | func isScalarTypescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/parsing/kdl`/isScalarType().(t modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.Typescip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/Type#) bool { |
| 269 | switch t { |
| 270 | case modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeStringscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeString., modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeIntscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeInt., modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeFloatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeFloat., modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeBoolscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeBool., modelscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/.TypeNullscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/model`/TypeNull.: |
| 271 | return true |
| 272 | } |
| 273 | return false |
| 274 | } |