Skip to content

Commit

Permalink
Use yq compact sequence indent for lima yaml
Browse files Browse the repository at this point in the history
The default sequence indent adds spaces, before the dash.

With compact sequence indent, the '- ' is part of indent.

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
  • Loading branch information
afbjorklund committed May 12, 2023
1 parent 05e85e5 commit 32c5970
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 4 additions & 2 deletions pkg/yqutil/yqutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ func EvaluateExpression(expression string, content []byte) ([]byte, error) {
yqlib.InitExpressionParser()

indent := 2
encoder := yqlib.NewYamlEncoder(indent, false, yqlib.ConfiguredYamlPreferences)
prefs := yqlib.NewDefaultYamlPreferences()
prefs.CompactSequenceIndent = true
encoder := yqlib.NewYamlEncoder(indent, false, prefs)
out := new(bytes.Buffer)
printer := yqlib.NewPrinter(encoder, yqlib.NewSinglePrinterWriter(out))
decoder := yqlib.NewYamlDecoder(yqlib.ConfiguredYamlPreferences)
decoder := yqlib.NewYamlDecoder(prefs)

streamEvaluator := yqlib.NewStreamEvaluator()
files := []string{tmpYAMLPath}
Expand Down
13 changes: 6 additions & 7 deletions pkg/yqutil/yqutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,18 @@ mounts:
# 🟢 Builtin default: value of location
mountPoint: null
`
// Note: yq will use canonical yaml, with indented sequences
// Note: yq will not explicitly quote strings, when not needed
expected := `
# Expose host directories to the guest, the mount point might be accessible from all UIDs in the guest
# 🟢 Builtin default: null (Mount nothing)
# 🔵 This file: Mount the home as read-only, /tmp/lima as writable
mounts:
- location: "~"
# Configure the mountPoint inside the guest.
# 🟢 Builtin default: value of location
mountPoint: null
- location: foo
mountPoint: bar
- location: "~"
# Configure the mountPoint inside the guest.
# 🟢 Builtin default: value of location
mountPoint: null
- location: foo
mountPoint: bar
`
out, err := EvaluateExpression(expression, []byte(content))
assert.NilError(t, err)
Expand Down

0 comments on commit 32c5970

Please sign in to comment.