Compare commits

...

14 Commits

Author SHA1 Message Date
Tommy Malmqvist
92bdd0681d
Merge 9ce5c8afee into 17f66dc6c6 2026-03-29 22:56:45 +06:00
dependabot[bot]
17f66dc6c6
Bump github.com/goccy/go-json from 0.10.5 to 0.10.6 (#2636)
Bumps [github.com/goccy/go-json](https://github.com/goccy/go-json) from 0.10.5 to 0.10.6.
- [Release notes](https://github.com/goccy/go-json/releases)
- [Changelog](https://github.com/goccy/go-json/blob/master/CHANGELOG.md)
- [Commits](https://github.com/goccy/go-json/compare/v0.10.5...v0.10.6)

---
updated-dependencies:
- dependency-name: github.com/goccy/go-json
  dependency-version: 0.10.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-26 20:42:41 +11:00
dependabot[bot]
dcb9c2a543
Bump github.com/pelletier/go-toml/v2 from 2.2.4 to 2.3.0 (#2637)
Bumps [github.com/pelletier/go-toml/v2](https://github.com/pelletier/go-toml) from 2.2.4 to 2.3.0.
- [Release notes](https://github.com/pelletier/go-toml/releases)
- [Commits](https://github.com/pelletier/go-toml/compare/v2.2.4...v2.3.0)

---
updated-dependencies:
- dependency-name: github.com/pelletier/go-toml/v2
  dependency-version: 2.3.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-26 20:42:19 +11:00
dependabot[bot]
8f5d876bf0
Bump github.com/fatih/color from 1.18.0 to 1.19.0 (#2638)
Bumps [github.com/fatih/color](https://github.com/fatih/color) from 1.18.0 to 1.19.0.
- [Release notes](https://github.com/fatih/color/releases)
- [Commits](https://github.com/fatih/color/compare/v1.18.0...v1.19.0)

---
updated-dependencies:
- dependency-name: github.com/fatih/color
  dependency-version: 1.19.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-26 20:42:06 +11:00
Copilot
7d8d3ab902
Replace gopkg.in/op/go-logging.v1 with log/slog (#2635)
* Initial plan

* Replace gopkg.in/op/go-logging.v1 with log/slog

Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>
Agent-Logs-Url: https://github.com/mikefarah/yq/sessions/aa9c12f4-21b9-4633-9868-6b56585b247f

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>
2026-03-26 20:41:54 +11:00
Mike Farah
11f4dc1a03 Bumping version 2026-03-26 10:08:43 +11:00
Mike Farah
0f4fb8d35e Bumping version 2026-03-26 10:03:01 +11:00
Mike Farah
80c319aa0c Fixing tests with latest linting rules 2026-03-26 09:29:51 +11:00
Terminal Chai
b25ae78545
fix: reset TOML decoder state between files (#2634)
* fix: reset TOML decoder between files

* test: fix TOML regression fixture spelling
2026-03-26 09:16:21 +11:00
cobyfrombrooklyn-bot
b151522485
fix: preserve original filename when using --front-matter (#2613)
When using --front-matter, yq creates a temporary file for the
extracted YAML content but replaces the original filename in args
with the temp file path. This caused the 'filename' operator to
return the temp file path instead of the original filename.

Added a filename alias mechanism: when front matter processing
replaces the file path, it registers the original filename as an
alias. The readDocuments and stream evaluator functions resolve
aliases before setting candidateNode.filename.

Fixes #2538

Co-authored-by: cobyfrombrooklyn-bot <cobyfrombrooklyn@gmail.com>
2026-03-26 09:06:20 +11:00
Tommy Malmqvist
9ce5c8afee Refactor Docker login process in action.yml to enhance image pulling logic. Added handling for successful and failed pulls with credentials and anonymous access. Mask sensitive values during login. 2025-09-18 07:31:47 +02:00
Tommy Malmqvist
f20f287d5b Mask sensitive values during Docker login in action.yml 2025-09-17 10:16:56 +02:00
Tommy Malmqvist
c8efd595fc Update README.md 2025-09-16 16:12:45 +02:00
Tommy Malmqvist
fc8a3fc3ce Enhance GitHub Action with custom registry support and input parameters. Updated action.yml to include optional inputs for image, registry, and authentication credentials. Refactored to use a composite action for improved container management. Updated README.md to reflect new features and usage examples. 2025-09-16 15:56:56 +02:00
67 changed files with 450 additions and 185 deletions

View File

@ -478,3 +478,4 @@ yq ".a.b[0].c = \"value\"" file.yaml
- "yes", "no" were dropped as boolean values in the yaml 1.2 standard - which is the standard yq assumes. - "yes", "no" were dropped as boolean values in the yaml 1.2 standard - which is the standard yq assumes.
See [tips and tricks](https://mikefarah.gitbook.io/yq/usage/tips-and-tricks) for more common problems and solutions. See [tips and tricks](https://mikefarah.gitbook.io/yq/usage/tips-and-tricks) for more common problems and solutions.

View File

@ -1,17 +1,105 @@
name: 'yq - portable yaml processor' name: "yq - portable yaml processor"
description: 'create, read, update, delete, merge, validate and do more with yaml' description: "create, read, update, delete, merge, validate and do more with yaml"
branding: branding:
icon: command icon: command
color: gray-dark color: gray-dark
inputs: inputs:
image:
description: 'Container image to run. Example: "mikefarah/yq:4-githubaction" or fully qualified "artifacts.example.com/repo/mikefarah/yq:4-githubaction".'
required: false
default: "mikefarah/yq:4-githubaction"
registry:
description: "Optional artifact repository hostname to prefix the `image`. Leave empty if your `image` already includes a registry."
required: false
default: ""
registry_username:
description: "Optional registry username for `docker login` (use with `registry_password`)."
required: false
default: ""
registry_password:
description: "Optional registry password for `docker login` (use with `registry_username`). Pass secrets via workflow `with:` from secrets."
required: false
default: ""
cmd: cmd:
description: 'The Command which should be run' description: "The Command which should be run"
required: true required: true
runs:
using: "composite"
steps:
- id: pull-with-credentials
name: Pull image using provided credentials
if: ${{ inputs.registry_username && inputs.registry_password && inputs.registry }}
shell: bash
env:
IMAGE_INPUT: ${{ inputs.image }}
REGISTRY: ${{ inputs.registry }}
REG_USER: ${{ inputs.registry_username }}
REG_PASS: ${{ inputs.registry_password }}
run: |
set -euo pipefail
IMAGE="$IMAGE_INPUT"
if [ -n "$REGISTRY" ]; then
REG="${REGISTRY%/}"
IMAGE="$REG/$IMAGE"
fi
echo "Using image: $IMAGE"
echo "Credentials provided; attempting docker login to $REGISTRY"
if [ -n "$REG_PASS" ]; then
echo "::add-mask::$REG_PASS"
fi
echo "$REG_PASS" | docker login "$REGISTRY" --username "$REG_USER" --password-stdin
if docker pull "$IMAGE" >/dev/null 2>&1; then
echo "Image pulled successfully after login."
else
echo "Failed to pull image after login; proceeding to run (docker run may fail)."
fi
- id: pull-anonymous
name: Pull image anonymously
if: ${{ !(inputs.registry_username && inputs.registry_password && inputs.registry) }}
shell: bash
env:
IMAGE_INPUT: ${{ inputs.image }}
REGISTRY: ${{ inputs.registry }}
run: |
set -euo pipefail
IMAGE="$IMAGE_INPUT"
if [ -n "$REGISTRY" ]; then
REG="${REGISTRY%/}"
IMAGE="$REG/$IMAGE"
fi
echo "Using image: $IMAGE"
echo "No credentials provided (or registry not set); attempting anonymous pull"
if docker pull "$IMAGE" >/dev/null 2>&1; then
echo "Anonymous pull succeeded."
else
echo "Anonymous pull failed; proceeding to run (docker run may fail if auth required)."
fi
- id: run
name: Run yq container
shell: bash
env:
IMAGE_INPUT: ${{ inputs.image }}
REGISTRY: ${{ inputs.registry }}
CMD_INPUT: ${{ inputs.cmd }}
run: |
set -euo pipefail
IMAGE="$IMAGE_INPUT"
if [ -n "$REGISTRY" ]; then
REG="${REGISTRY%/}"
IMAGE="$REG/$IMAGE"
fi
echo "Using image: $IMAGE"
RC=0
OUTPUT=$(docker run --rm -v "$GITHUB_WORKSPACE":/work -w /work "$IMAGE" sh -lc "$CMD_INPUT" 2>&1) || RC=$?
echo "result<<EOF" >> $GITHUB_OUTPUT
echo "$OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
if [ "$RC" -ne 0 ]; then
exit "$RC"
fi
outputs: outputs:
result: result:
description: "The complete result from the yq command being run" description: "The complete result from the yq command being run"
runs: value: ${{ steps.run.outputs.result }}
using: 'docker'
image: 'docker://mikefarah/yq:4-githubaction'
args:
- ${{ inputs.cmd }}

View File

@ -101,12 +101,15 @@ func evaluateAll(cmd *cobra.Command, args []string) (cmdError error) {
} }
if frontMatter != "" { if frontMatter != "" {
originalFilename := args[0]
frontMatterHandler := yqlib.NewFrontMatterHandler(args[0]) frontMatterHandler := yqlib.NewFrontMatterHandler(args[0])
err = frontMatterHandler.Split() err = frontMatterHandler.Split()
if err != nil { if err != nil {
return err return err
} }
args[0] = frontMatterHandler.GetYamlFrontMatterFilename() args[0] = frontMatterHandler.GetYamlFrontMatterFilename()
yqlib.SetFilenameAlias(args[0], originalFilename)
defer yqlib.ClearFilenameAliases()
if frontMatter == "process" { if frontMatter == "process" {
reader := frontMatterHandler.GetContentReader() reader := frontMatterHandler.GetContentReader()

View File

@ -13,6 +13,7 @@ func TestCreateEvaluateAllCommand(t *testing.T) {
if cmd == nil { if cmd == nil {
t.Fatal("createEvaluateAllCommand returned nil") t.Fatal("createEvaluateAllCommand returned nil")
return
} }
// Test basic command properties // Test basic command properties

View File

@ -122,12 +122,15 @@ func evaluateSequence(cmd *cobra.Command, args []string) (cmdError error) {
if frontMatter != "" { if frontMatter != "" {
yqlib.GetLogger().Debug("using front matter handler") yqlib.GetLogger().Debug("using front matter handler")
originalFilename := args[0]
frontMatterHandler := yqlib.NewFrontMatterHandler(args[0]) frontMatterHandler := yqlib.NewFrontMatterHandler(args[0])
err = frontMatterHandler.Split() err = frontMatterHandler.Split()
if err != nil { if err != nil {
return err return err
} }
args[0] = frontMatterHandler.GetYamlFrontMatterFilename() args[0] = frontMatterHandler.GetYamlFrontMatterFilename()
yqlib.SetFilenameAlias(args[0], originalFilename)
defer yqlib.ClearFilenameAliases()
if frontMatter == "process" { if frontMatter == "process" {
reader := frontMatterHandler.GetContentReader() reader := frontMatterHandler.GetContentReader()

View File

@ -13,6 +13,7 @@ func TestCreateEvaluateSequenceCommand(t *testing.T) {
if cmd == nil { if cmd == nil {
t.Fatal("createEvaluateSequenceCommand returned nil") t.Fatal("createEvaluateSequenceCommand returned nil")
return
} }
// Test basic command properties // Test basic command properties

View File

@ -2,12 +2,12 @@ package cmd
import ( import (
"fmt" "fmt"
"log/slog"
"os" "os"
"strings" "strings"
"github.com/mikefarah/yq/v4/pkg/yqlib" "github.com/mikefarah/yq/v4/pkg/yqlib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
logging "gopkg.in/op/go-logging.v1"
) )
type runeValue rune type runeValue rune
@ -68,30 +68,21 @@ yq -P -oy sample.json
}, },
PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
cmd.SetOut(cmd.OutOrStdout()) cmd.SetOut(cmd.OutOrStdout())
level := logging.WARNING
stringFormat := `[%{level}] %{color}%{time:15:04:05}%{color:reset} %{message}`
// when NO_COLOR environment variable presents and not an empty string the coloured output should be disabled; // when NO_COLOR environment variable presents and not an empty string the coloured output should be disabled;
// refer to no-color.org // refer to no-color.org
forceNoColor = forceNoColor || os.Getenv("NO_COLOR") != "" forceNoColor = forceNoColor || os.Getenv("NO_COLOR") != ""
if verbose && forceNoColor { level := slog.LevelWarn
level = logging.DEBUG if verbose {
stringFormat = `[%{level:5.5s}] %{time:15:04:05} %{shortfile:-33s} %{shortfunc:-25s} %{message}` level = slog.LevelDebug
} else if verbose {
level = logging.DEBUG
stringFormat = `[%{level:5.5s}] %{color}%{time:15:04:05}%{color:bold} %{shortfile:-33s} %{shortfunc:-25s}%{color:reset} %{message}`
} else if forceNoColor {
stringFormat = `[%{level}] %{time:15:04:05} %{message}`
} }
var format = logging.MustStringFormatter(stringFormat) yqlib.GetLogger().SetLevel(level)
var backend = logging.AddModuleLevel( opts := &slog.HandlerOptions{Level: level, AddSource: verbose}
logging.NewBackendFormatter(logging.NewLogBackend(os.Stderr, "", 0), format)) handler := slog.NewTextHandler(os.Stderr, opts)
yqlib.GetLogger().SetSlogger(slog.New(handler))
backend.SetLevel(level, "")
logging.SetBackend(backend)
yqlib.InitExpressionParser() yqlib.InitExpressionParser()
return nil return nil

View File

@ -195,6 +195,7 @@ func TestNew(t *testing.T) {
if rootCmd == nil { if rootCmd == nil {
t.Fatal("New() returned nil") t.Fatal("New() returned nil")
return
} }
// Test basic command properties // Test basic command properties

View File

@ -3,12 +3,12 @@ package cmd
import ( import (
"fmt" "fmt"
"io" "io"
"log/slog"
"os" "os"
"strings" "strings"
"github.com/mikefarah/yq/v4/pkg/yqlib" "github.com/mikefarah/yq/v4/pkg/yqlib"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"gopkg.in/op/go-logging.v1"
) )
func isAutomaticOutputFormat() bool { func isAutomaticOutputFormat() bool {
@ -104,8 +104,8 @@ func configureFormats(args []string) error {
return err return err
} }
yqlib.GetLogger().Debug("Using input format %v", inputFormat) yqlib.GetLogger().Debugf("Using input format %v", inputFormat)
yqlib.GetLogger().Debug("Using output format %v", outputFormat) yqlib.GetLogger().Debugf("Using output format %v", outputFormat)
return nil return nil
} }
@ -117,7 +117,7 @@ func configureInputFormat(inputFilename string) error {
_, err := yqlib.FormatFromString(inputFormat) _, err := yqlib.FormatFromString(inputFormat)
if err != nil { if err != nil {
// unknown file type, default to yaml // unknown file type, default to yaml
yqlib.GetLogger().Debug("Unknown file format extension '%v', defaulting to yaml", inputFormat) yqlib.GetLogger().Debugf("Unknown file format extension '%v', defaulting to yaml", inputFormat)
inputFormat = "yaml" inputFormat = "yaml"
if isAutomaticOutputFormat() { if isAutomaticOutputFormat() {
outputFormat = "yaml" outputFormat = "yaml"
@ -132,7 +132,7 @@ func configureInputFormat(inputFilename string) error {
// //
outputFormat = yqlib.FormatStringFromFilename(inputFilename) outputFormat = yqlib.FormatStringFromFilename(inputFilename)
if inputFilename != "-" { if inputFilename != "-" {
yqlib.GetLogger().Warning("yq default output is now 'auto' (based on the filename extension). Normally yq would output '%v', but for backwards compatibility 'yaml' has been set. Please use -oy to specify yaml, or drop the -p flag.", outputFormat) yqlib.GetLogger().Warningf("yq default output is now 'auto' (based on the filename extension). Normally yq would output '%v', but for backwards compatibility 'yaml' has been set. Please use -oy to specify yaml, or drop the -p flag.", outputFormat)
} }
outputFormat = "yaml" outputFormat = "yaml"
} }
@ -235,7 +235,7 @@ func maybeFile(str string) bool {
yqlib.GetLogger().Debugf("checking '%v' is a file", str) yqlib.GetLogger().Debugf("checking '%v' is a file", str)
stat, err := os.Stat(str) // #nosec stat, err := os.Stat(str) // #nosec
result := err == nil && !stat.IsDir() result := err == nil && !stat.IsDir()
if yqlib.GetLogger().IsEnabledFor(logging.DEBUG) { if yqlib.GetLogger().IsEnabledFor(slog.LevelDebug) {
if err != nil { if err != nil {
yqlib.GetLogger().Debugf("error: %v", err) yqlib.GetLogger().Debugf("error: %v", err)
} else { } else {
@ -280,7 +280,7 @@ func processArgs(originalArgs []string) (string, []string, error) {
if expressionFile == "" && maybeFirstArgIsAFile && strings.HasSuffix(args[0], ".yq") { if expressionFile == "" && maybeFirstArgIsAFile && strings.HasSuffix(args[0], ".yq") {
// lets check if an expression file was given // lets check if an expression file was given
yqlib.GetLogger().Debug("Assuming arg %v is an expression file", args[0]) yqlib.GetLogger().Debugf("Assuming arg %v is an expression file", args[0])
expressionFile = args[0] expressionFile = args[0]
args = args[1:] args = args[1:]
} }
@ -296,7 +296,7 @@ func processArgs(originalArgs []string) (string, []string, error) {
yqlib.GetLogger().Debugf("processed args: %v", args) yqlib.GetLogger().Debugf("processed args: %v", args)
if expression == "" && len(args) > 0 && args[0] != "-" && !maybeFile(args[0]) { if expression == "" && len(args) > 0 && args[0] != "-" && !maybeFile(args[0]) {
yqlib.GetLogger().Debug("assuming expression is '%v'", args[0]) yqlib.GetLogger().Debugf("assuming expression is '%v'", args[0])
expression = args[0] expression = args[0]
args = args[1:] args = args[1:]
} }

View File

@ -11,7 +11,7 @@ var (
GitDescribe string GitDescribe string
// Version is main version number that is being run at the moment. // Version is main version number that is being run at the moment.
Version = "v4.52.4" Version = "v4.52.5"
// VersionPrerelease is a pre-release marker for the version. If this is "" (empty string) // VersionPrerelease is a pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release // then it means that it is a final release. Otherwise, this is a pre-release

7
go.mod
View File

@ -6,14 +6,14 @@ require (
github.com/alecthomas/repr v0.5.2 github.com/alecthomas/repr v0.5.2
github.com/dimchansky/utfbom v1.1.1 github.com/dimchansky/utfbom v1.1.1
github.com/elliotchance/orderedmap v1.8.0 github.com/elliotchance/orderedmap v1.8.0
github.com/fatih/color v1.18.0 github.com/fatih/color v1.19.0
github.com/go-ini/ini v1.67.0 github.com/go-ini/ini v1.67.0
github.com/goccy/go-json v0.10.5 github.com/goccy/go-json v0.10.6
github.com/goccy/go-yaml v1.19.2 github.com/goccy/go-yaml v1.19.2
github.com/hashicorp/hcl/v2 v2.24.0 github.com/hashicorp/hcl/v2 v2.24.0
github.com/jinzhu/copier v0.4.0 github.com/jinzhu/copier v0.4.0
github.com/magiconair/properties v1.8.10 github.com/magiconair/properties v1.8.10
github.com/pelletier/go-toml/v2 v2.2.4 github.com/pelletier/go-toml/v2 v2.3.0
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e
github.com/spf13/cobra v1.10.2 github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10 github.com/spf13/pflag v1.0.10
@ -23,7 +23,6 @@ require (
golang.org/x/mod v0.34.0 golang.org/x/mod v0.34.0
golang.org/x/net v0.52.0 golang.org/x/net v0.52.0
golang.org/x/text v0.35.0 golang.org/x/text v0.35.0
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
) )
require ( require (

14
go.sum
View File

@ -18,14 +18,14 @@ github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi
github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE= github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE=
github.com/elliotchance/orderedmap v1.8.0 h1:TrOREecvh3JbS+NCgwposXG5ZTFHtEsQiCGOhPElnMw= github.com/elliotchance/orderedmap v1.8.0 h1:TrOREecvh3JbS+NCgwposXG5ZTFHtEsQiCGOhPElnMw=
github.com/elliotchance/orderedmap v1.8.0/go.mod h1:wsDwEaX5jEoyhbs7x93zk2H/qv0zwuhg4inXhDkYqys= github.com/elliotchance/orderedmap v1.8.0/go.mod h1:wsDwEaX5jEoyhbs7x93zk2H/qv0zwuhg4inXhDkYqys=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE=
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= github.com/goccy/go-json v0.10.6 h1:p8HrPJzOakx/mn/bQtjgNjdTcN+/S6FcG2CTtQOrHVU=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= github.com/goccy/go-json v0.10.6/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM= github.com/goccy/go-yaml v1.19.2 h1:PmFC1S6h8ljIz6gMRBopkjP1TVT7xuwrButHID66PoM=
github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/goccy/go-yaml v1.19.2/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
@ -46,8 +46,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.3.0 h1:k59bC/lIZREW0/iVaQR8nDHxVq8OVlIzYCOJf421CaM=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pelletier/go-toml/v2 v2.3.0/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e h1:aoZm08cpOy4WuID//EZDgcC4zIxODThtZNPirFr42+A=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@ -84,7 +84,5 @@ golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA=
golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k= golang.org/x/tools v0.42.0 h1:uNgphsn75Tdz5Ji2q36v/nsFSfR/9BRFvqhGBaJGd5k=
golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0= golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473 h1:6D+BvnJ/j6e222UW8s2qTSe3wGBtvo0MbVQG/c5k8RE=
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473/go.mod h1:N1eN2tsCx0Ydtgjl4cqmbRCsY4/+z4cYDeqwZTk6zog=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -54,3 +54,25 @@ func TestAllAtOnceEvaluateNodes(t *testing.T) {
test.AssertResultComplex(t, tt.expected, resultsToString(t, list)) test.AssertResultComplex(t, tt.expected, resultsToString(t, list))
} }
} }
func TestTomlDecoderCanBeReinitializedAcrossDocuments(t *testing.T) {
decoder := NewTomlDecoder()
firstDocuments, err := ReadDocuments(strings.NewReader("id = \"Foobar\"\n"), decoder)
if err != nil {
t.Fatalf("failed to read first TOML document: %v", err)
}
if firstDocuments.Len() != 1 {
t.Fatalf("expected first document count to be 1, got %d", firstDocuments.Len())
}
test.AssertResult(t, "Foobar", firstDocuments.Front().Value.(*CandidateNode).Content[1].Value)
secondDocuments, err := ReadDocuments(strings.NewReader("id = \"Banana\"\n"), decoder)
if err != nil {
t.Fatalf("failed to read second TOML document: %v", err)
}
if secondDocuments.Len() != 1 {
t.Fatalf("expected second document count to be 1, got %d", secondDocuments.Len())
}
test.AssertResult(t, "Banana", secondDocuments.Front().Value.(*CandidateNode).Content[1].Value)
}

View File

@ -323,11 +323,11 @@ func (n *CandidateNode) guessTagFromCustomType() string {
dataBucket, errorReading := parseSnippet(n.Value) dataBucket, errorReading := parseSnippet(n.Value)
if errorReading != nil { if errorReading != nil {
log.Debug("guessTagFromCustomType: could not guess underlying tag type %v", errorReading) log.Debugf("guessTagFromCustomType: could not guess underlying tag type %v", errorReading)
return n.Tag return n.Tag
} }
guessedTag := dataBucket.Tag guessedTag := dataBucket.Tag
log.Info("im guessing the tag %v is a %v", n.Tag, guessedTag) log.Infof("im guessing the tag %v is a %v", n.Tag, guessedTag)
return guessedTag return guessedTag
} }
@ -445,7 +445,7 @@ func (n *CandidateNode) UpdateFrom(other *CandidateNode, prefs assignPreferences
} }
func (n *CandidateNode) UpdateAttributesFrom(other *CandidateNode, prefs assignPreferences) { func (n *CandidateNode) UpdateAttributesFrom(other *CandidateNode, prefs assignPreferences) {
log.Debug("UpdateAttributesFrom: n: %v other: %v", NodeToString(n), NodeToString(other)) log.Debugf("UpdateAttributesFrom: n: %v other: %v", NodeToString(n), NodeToString(other))
if n.Kind != other.Kind { if n.Kind != other.Kind {
// clear out the contents when switching to a different type // clear out the contents when switching to a different type
// e.g. map to array // e.g. map to array

View File

@ -36,13 +36,13 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
switch commentMapComment.Position { switch commentMapComment.Position {
case yaml.CommentHeadPosition: case yaml.CommentHeadPosition:
o.HeadComment = comment.String() o.HeadComment = comment.String()
log.Debug("its a head comment %v", comment.String()) log.Debugf("its a head comment %v", comment.String())
case yaml.CommentLinePosition: case yaml.CommentLinePosition:
o.LineComment = comment.String() o.LineComment = comment.String()
log.Debug("its a line comment %v", comment.String()) log.Debugf("its a line comment %v", comment.String())
case yaml.CommentFootPosition: case yaml.CommentFootPosition:
o.FootComment = comment.String() o.FootComment = comment.String()
log.Debug("its a foot comment %v", comment.String()) log.Debugf("its a foot comment %v", comment.String())
} }
} }
} }
@ -93,8 +93,8 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
log.Debugf("folded Type %v", astLiteral.Start.Type) log.Debugf("folded Type %v", astLiteral.Start.Type)
o.Style = FoldedStyle o.Style = FoldedStyle
} }
log.Debug("start value: %v ", node.(*ast.LiteralNode).Start.Value) log.Debugf("start value: %v ", node.(*ast.LiteralNode).Start.Value)
log.Debug("start value: %v ", node.(*ast.LiteralNode).Start.Type) log.Debugf("start value: %v ", node.(*ast.LiteralNode).Start.Type)
// TODO: here I could put the original value with line breaks // TODO: here I could put the original value with line breaks
// to solve the multiline > problem // to solve the multiline > problem
o.Value = astLiteral.Value.Value o.Value = astLiteral.Value.Value
@ -187,7 +187,7 @@ func (o *CandidateNode) UnmarshalGoccyYAML(node ast.Node, cm yaml.CommentMap, an
} }
func (o *CandidateNode) goccyProcessMappingValueNode(mappingEntry *ast.MappingValueNode, cm yaml.CommentMap, anchorMap map[string]*CandidateNode) error { func (o *CandidateNode) goccyProcessMappingValueNode(mappingEntry *ast.MappingValueNode, cm yaml.CommentMap, anchorMap map[string]*CandidateNode) error {
log.Debug("UnmarshalYAML MAP KEY entry %v", mappingEntry.Key) log.Debugf("UnmarshalYAML MAP KEY entry %v", mappingEntry.Key)
// AddKeyValueFirst because it clones the nodes, and we want to have the real refs when Unmarshalling // AddKeyValueFirst because it clones the nodes, and we want to have the real refs when Unmarshalling
// particularly for the anchorMap // particularly for the anchorMap
@ -197,7 +197,7 @@ func (o *CandidateNode) goccyProcessMappingValueNode(mappingEntry *ast.MappingVa
return err return err
} }
log.Debug("UnmarshalYAML MAP VALUE entry %v", mappingEntry.Value) log.Debugf("UnmarshalYAML MAP VALUE entry %v", mappingEntry.Value)
if err := valueNode.UnmarshalGoccyYAML(mappingEntry.Value, cm, anchorMap); err != nil { if err := valueNode.UnmarshalGoccyYAML(mappingEntry.Value, cm, anchorMap); err != nil {
return err return err
} }

View File

@ -120,7 +120,7 @@ func (o *CandidateNode) UnmarshalJSON(data []byte) error {
if err != nil { if err != nil {
return err return err
} }
log.Debug("UnmarshalJSON - scalar is %v", scalar) log.Debugf("UnmarshalJSON - scalar is %v", scalar)
return o.setScalarFromJson(scalar) return o.setScalarFromJson(scalar)

View File

@ -55,13 +55,13 @@ func (o *CandidateNode) copyFromYamlNode(node *yaml.Node, anchorMap map[string]*
if o.Anchor != "" { if o.Anchor != "" {
anchorMap[o.Anchor] = o anchorMap[o.Anchor] = o
log.Debug("set anchor %v to %v", o.Anchor, NodeToString(o)) log.Debugf("set anchor %v to %v", o.Anchor, NodeToString(o))
} }
// its a single alias // its a single alias
if node.Alias != nil && node.Alias.Anchor != "" { if node.Alias != nil && node.Alias.Anchor != "" {
o.Alias = anchorMap[node.Alias.Anchor] o.Alias = anchorMap[node.Alias.Anchor]
log.Debug("set alias to %v", NodeToString(anchorMap[node.Alias.Anchor])) log.Debugf("set alias to %v", NodeToString(anchorMap[node.Alias.Anchor]))
} }
o.HeadComment = node.HeadComment o.HeadComment = node.HeadComment
o.LineComment = node.LineComment o.LineComment = node.LineComment
@ -106,7 +106,7 @@ func (o *CandidateNode) UnmarshalYAML(node *yaml.Node, anchorMap map[string]*Can
log.Debugf("UnmarshalYAML %v", node.Tag) log.Debugf("UnmarshalYAML %v", node.Tag)
switch node.Kind { switch node.Kind {
case yaml.AliasNode: case yaml.AliasNode:
log.Debug("UnmarshalYAML - alias from yaml: %v", o.Tag) log.Debugf("UnmarshalYAML - alias from yaml: %v", o.Tag)
o.Kind = AliasNode o.Kind = AliasNode
o.copyFromYamlNode(node, anchorMap) o.copyFromYamlNode(node, anchorMap)
return nil return nil
@ -176,15 +176,15 @@ func (o *CandidateNode) UnmarshalYAML(node *yaml.Node, anchorMap map[string]*Can
} }
func (o *CandidateNode) MarshalYAML() (*yaml.Node, error) { func (o *CandidateNode) MarshalYAML() (*yaml.Node, error) {
log.Debug("MarshalYAML to yaml: %v", o.Tag) log.Debugf("MarshalYAML to yaml: %v", o.Tag)
switch o.Kind { switch o.Kind {
case AliasNode: case AliasNode:
log.Debug("MarshalYAML - alias to yaml: %v", o.Tag) log.Debugf("MarshalYAML - alias to yaml: %v", o.Tag)
target := &yaml.Node{Kind: yaml.AliasNode} target := &yaml.Node{Kind: yaml.AliasNode}
o.copyToYamlNode(target) o.copyToYamlNode(target)
return target, nil return target, nil
case ScalarNode: case ScalarNode:
log.Debug("MarshalYAML - scalar: %v", o.Value) log.Debugf("MarshalYAML - scalar: %v", o.Value)
target := &yaml.Node{Kind: yaml.ScalarNode} target := &yaml.Node{Kind: yaml.ScalarNode}
o.copyToYamlNode(target) o.copyToYamlNode(target)
return target, nil return target, nil

View File

@ -18,7 +18,7 @@ func changeOwner(info fs.FileInfo, file *os.File) error {
// this happens with snap confinement // this happens with snap confinement
// not really a big issue as users can chown // not really a big issue as users can chown
// the file themselves if required. // the file themselves if required.
log.Info("Skipping chown: %v", err) log.Infof("Skipping chown: %v", err)
} }
} }
return nil return nil

View File

@ -3,9 +3,8 @@ package yqlib
import ( import (
"container/list" "container/list"
"fmt" "fmt"
"log/slog"
"time" "time"
logging "gopkg.in/op/go-logging.v1"
) )
type Context struct { type Context struct {
@ -75,7 +74,7 @@ func (n *Context) ChildContext(results *list.List) Context {
} }
func (n *Context) ToString() string { func (n *Context) ToString() string {
if !log.IsEnabledFor(logging.DEBUG) { if !log.IsEnabledFor(slog.LevelDebug) {
return "" return ""
} }
result := fmt.Sprintf("Context\nDontAutoCreate: %v\n", n.DontAutoCreate) result := fmt.Sprintf("Context\nDontAutoCreate: %v\n", n.DontAutoCreate)

View File

@ -2,11 +2,11 @@ package yqlib
import ( import (
"container/list" "container/list"
"log/slog"
"strings" "strings"
"testing" "testing"
"github.com/mikefarah/yq/v4/test" "github.com/mikefarah/yq/v4/test"
logging "gopkg.in/op/go-logging.v1"
) )
func TestChildContext(t *testing.T) { func TestChildContext(t *testing.T) {
@ -155,8 +155,8 @@ func TestToString(t *testing.T) {
test.AssertResultComplex(t, "", result) test.AssertResultComplex(t, "", result)
// Test with debug logging enabled // Test with debug logging enabled
logging.SetLevel(logging.DEBUG, "") GetLogger().SetLevel(slog.LevelDebug)
defer logging.SetLevel(logging.INFO, "") // Reset to default defer GetLogger().SetLevel(slog.LevelWarn) // Reset to default
result2 := context.ToString() result2 := context.ToString()
test.AssertResultComplex(t, true, len(result2) > 0) test.AssertResultComplex(t, true, len(result2) > 0)

View File

@ -2,8 +2,7 @@ package yqlib
import ( import (
"fmt" "fmt"
"log/slog"
logging "gopkg.in/op/go-logging.v1"
) )
type DataTreeNavigator interface { type DataTreeNavigator interface {
@ -55,7 +54,7 @@ func (d *dataTreeNavigator) GetMatchingNodes(context Context, expressionNode *Ex
return context, nil return context, nil
} }
log.Debugf("Processing Op: %v", expressionNode.Operation.toString()) log.Debugf("Processing Op: %v", expressionNode.Operation.toString())
if log.IsEnabledFor(logging.DEBUG) { if log.IsEnabledFor(slog.LevelDebug) {
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
log.Debug(NodeToString(el.Value.(*CandidateNode))) log.Debug(NodeToString(el.Value.(*CandidateNode)))
} }

View File

@ -68,7 +68,7 @@ func mustProcessFormatScenario(s formatScenario, decoder Decoder, encoder Encode
result, err := processFormatScenario(s, decoder, encoder) result, err := processFormatScenario(s, decoder, encoder)
if err != nil { if err != nil {
log.Error("Bad scenario %v: %w", s.description, err) log.Errorf("Bad scenario %v: %v", s.description, err)
return fmt.Sprintf("Bad scenario %v: %v", s.description, err.Error()) return fmt.Sprintf("Bad scenario %v: %v", s.description, err.Error())
} }
return result return result

View File

@ -44,6 +44,7 @@ func (dec *tomlDecoder) Init(reader io.Reader) error {
} }
dec.pendingComments = make([]string, 0) dec.pendingComments = make([]string, 0)
dec.firstContentSeen = false dec.firstContentSeen = false
dec.finished = false
return nil return nil
} }
@ -105,7 +106,7 @@ func (dec *tomlDecoder) decodeKeyValuesIntoMap(rootMap *CandidateNode, tomlNode
for dec.parser.NextExpression() { for dec.parser.NextExpression() {
nextItem := dec.parser.Expression() nextItem := dec.parser.Expression()
log.Debug("decodeKeyValuesIntoMap -- next exp, its a %v", nextItem.Kind) log.Debugf("decodeKeyValuesIntoMap -- next exp, its a %v", nextItem.Kind)
switch nextItem.Kind { switch nextItem.Kind {
case toml.KeyValue: case toml.KeyValue:
@ -117,7 +118,7 @@ func (dec *tomlDecoder) decodeKeyValuesIntoMap(rootMap *CandidateNode, tomlNode
dec.pendingComments = append(dec.pendingComments, string(nextItem.Data)) dec.pendingComments = append(dec.pendingComments, string(nextItem.Data))
default: default:
// run out of key values // run out of key values
log.Debug("done in decodeKeyValuesIntoMap, gota a %v", nextItem.Kind) log.Debugf("done in decodeKeyValuesIntoMap, gota a %v", nextItem.Kind)
return true, nil return true, nil
} }
} }
@ -270,7 +271,7 @@ func (dec *tomlDecoder) Decode() (*CandidateNode, error) {
currentNode := dec.parser.Expression() currentNode := dec.parser.Expression()
log.Debug("currentNode: %v ", currentNode.Kind) log.Debugf("currentNode: %v ", currentNode.Kind)
runAgainstCurrentExp, err = dec.processTopLevelNode(currentNode) runAgainstCurrentExp, err = dec.processTopLevelNode(currentNode)
if err != nil { if err != nil {
return dec.rootMap, err return dec.rootMap, err
@ -297,7 +298,7 @@ func (dec *tomlDecoder) Decode() (*CandidateNode, error) {
func (dec *tomlDecoder) processTopLevelNode(currentNode *toml.Node) (bool, error) { func (dec *tomlDecoder) processTopLevelNode(currentNode *toml.Node) (bool, error) {
var runAgainstCurrentExp bool var runAgainstCurrentExp bool
var err error var err error
log.Debug("processTopLevelNode: Going to process %v state is current %v", currentNode.Kind, NodeToString(dec.rootMap)) log.Debugf("processTopLevelNode: Going to process %v state is current %v", currentNode.Kind, NodeToString(dec.rootMap))
switch currentNode.Kind { switch currentNode.Kind {
case toml.Comment: case toml.Comment:
// Collect comment to attach to next element // Collect comment to attach to next element
@ -325,7 +326,7 @@ func (dec *tomlDecoder) processTopLevelNode(currentNode *toml.Node) (bool, error
runAgainstCurrentExp, err = dec.decodeKeyValuesIntoMap(dec.rootMap, currentNode) runAgainstCurrentExp, err = dec.decodeKeyValuesIntoMap(dec.rootMap, currentNode)
} }
log.Debug("processTopLevelNode: DONE Processing state is now %v", NodeToString(dec.rootMap)) log.Debugf("processTopLevelNode: DONE Processing state is now %v", NodeToString(dec.rootMap))
return runAgainstCurrentExp, err return runAgainstCurrentExp, err
} }
@ -333,7 +334,7 @@ func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) {
log.Debug("Enter processTable") log.Debug("Enter processTable")
child := currentNode.Child() child := currentNode.Child()
fullPath := dec.getFullPath(child) fullPath := dec.getFullPath(child)
log.Debug("fullpath: %v", fullPath) log.Debugf("fullpath: %v", fullPath)
c := Context{} c := Context{}
c = c.SingleChildContext(dec.rootMap) c = c.SingleChildContext(dec.rootMap)
@ -401,7 +402,7 @@ func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) {
} }
func (dec *tomlDecoder) arrayAppend(context Context, path []interface{}, rhsNode *CandidateNode) error { func (dec *tomlDecoder) arrayAppend(context Context, path []interface{}, rhsNode *CandidateNode) error {
log.Debug("arrayAppend to path: %v,%v", path, NodeToString(rhsNode)) log.Debugf("arrayAppend to path: %v,%v", path, NodeToString(rhsNode))
rhsCandidateNode := &CandidateNode{ rhsCandidateNode := &CandidateNode{
Kind: SequenceNode, Kind: SequenceNode,
Tag: "!!seq", Tag: "!!seq",
@ -426,7 +427,7 @@ func (dec *tomlDecoder) processArrayTable(currentNode *toml.Node) (bool, error)
log.Debug("Enter processArrayTable") log.Debug("Enter processArrayTable")
child := currentNode.Child() child := currentNode.Child()
fullPath := dec.getFullPath(child) fullPath := dec.getFullPath(child)
log.Debug("Fullpath: %v", fullPath) log.Debugf("Fullpath: %v", fullPath)
c := Context{} c := Context{}
c = c.SingleChildContext(dec.rootMap) c = c.SingleChildContext(dec.rootMap)

View File

@ -64,7 +64,7 @@ func (dec *xmlDecoder) processComment(c string) string {
} }
func (dec *xmlDecoder) createMap(n *xmlNode) (*CandidateNode, error) { func (dec *xmlDecoder) createMap(n *xmlNode) (*CandidateNode, error) {
log.Debug("createMap: headC: %v, lineC: %v, footC: %v", n.HeadComment, n.LineComment, n.FootComment) log.Debugf("createMap: headC: %v, lineC: %v, footC: %v", n.HeadComment, n.LineComment, n.FootComment)
yamlNode := &CandidateNode{Kind: MappingNode, Tag: "!!map"} yamlNode := &CandidateNode{Kind: MappingNode, Tag: "!!map"}
if len(n.Data) > 0 { if len(n.Data) > 0 {
@ -92,7 +92,7 @@ func (dec *xmlDecoder) createMap(n *xmlNode) (*CandidateNode, error) {
log.Debugf("label=%v, i=%v, keyValuePair.FootComment: %v", label, i, keyValuePair.FootComment) log.Debugf("label=%v, i=%v, keyValuePair.FootComment: %v", label, i, keyValuePair.FootComment)
labelNode.FootComment = dec.processComment(keyValuePair.FootComment) labelNode.FootComment = dec.processComment(keyValuePair.FootComment)
log.Debug("len of children in %v is %v", label, len(children)) log.Debugf("len of children in %v is %v", label, len(children))
if len(children) > 1 { if len(children) > 1 {
valueNode, err = dec.createSequence(children) valueNode, err = dec.createSequence(children)
if err != nil { if err != nil {
@ -105,7 +105,7 @@ func (dec *xmlDecoder) createMap(n *xmlNode) (*CandidateNode, error) {
if len(children[0].Children) == 0 && children[0].HeadComment != "" { if len(children[0].Children) == 0 && children[0].HeadComment != "" {
if len(children[0].Data) > 0 { if len(children[0].Data) > 0 {
log.Debug("scalar comment hack, currentlabel [%v]", labelNode.HeadComment) log.Debugf("scalar comment hack, currentlabel [%v]", labelNode.HeadComment)
labelNode.HeadComment = joinComments([]string{labelNode.HeadComment, strings.TrimSpace(children[0].HeadComment)}, "\n") labelNode.HeadComment = joinComments([]string{labelNode.HeadComment, strings.TrimSpace(children[0].HeadComment)}, "\n")
children[0].HeadComment = "" children[0].HeadComment = ""
} else { } else {
@ -151,7 +151,7 @@ func (dec *xmlDecoder) convertToYamlNode(n *xmlNode) (*CandidateNode, error) {
scalar := dec.createValueNodeFromData(n.Data) scalar := dec.createValueNodeFromData(n.Data)
log.Debug("scalar (%v), headC: %v, lineC: %v, footC: %v", scalar.Tag, n.HeadComment, n.LineComment, n.FootComment) log.Debugf("scalar (%v), headC: %v, lineC: %v, footC: %v", scalar.Tag, n.HeadComment, n.LineComment, n.FootComment)
scalar.HeadComment = dec.processComment(n.HeadComment) scalar.HeadComment = dec.processComment(n.HeadComment)
scalar.LineComment = dec.processComment(n.LineComment) scalar.LineComment = dec.processComment(n.LineComment)
if scalar.Tag == "!!seq" { if scalar.Tag == "!!seq" {
@ -211,17 +211,17 @@ func (n *xmlNode) AddChild(s string, c *xmlNode) {
if n.Children == nil { if n.Children == nil {
n.Children = make([]*xmlChildrenKv, 0) n.Children = make([]*xmlChildrenKv, 0)
} }
log.Debug("looking for %s", s) log.Debugf("looking for %s", s)
// see if we can find an existing entry to add to // see if we can find an existing entry to add to
for _, childEntry := range n.Children { for _, childEntry := range n.Children {
if childEntry.K == s { if childEntry.K == s {
log.Debug("found it, appending an entry%s", s) log.Debugf("found it, appending an entry%s", s)
childEntry.V = append(childEntry.V, c) childEntry.V = append(childEntry.V, c)
log.Debug("yay len of children in %v is %v", s, len(childEntry.V)) log.Debugf("yay len of children in %v is %v", s, len(childEntry.V))
return return
} }
} }
log.Debug("not there, making a new one %s", s) log.Debugf("not there, making a new one %s", s)
n.Children = append(n.Children, &xmlChildrenKv{K: s, V: []*xmlNode{c}}) n.Children = append(n.Children, &xmlChildrenKv{K: s, V: []*xmlNode{c}})
} }
@ -267,7 +267,7 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
switch se := t.(type) { switch se := t.(type) {
case xml.StartElement: case xml.StartElement:
log.Debug("start element %v", se.Name.Local) log.Debugf("start element %v", se.Name.Local)
elem.state = "started" elem.state = "started"
// Build new a new current element and link it to its parent // Build new a new current element and link it to its parent
var label = se.Name.Local var label = se.Name.Local
@ -302,14 +302,14 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
if len(newBit) > 0 { if len(newBit) > 0 {
elem.n.Data = append(elem.n.Data, newBit) elem.n.Data = append(elem.n.Data, newBit)
elem.state = "chardata" elem.state = "chardata"
log.Debug("chardata [%v] for %v", elem.n.Data, elem.label) log.Debugf("chardata [%v] for %v", elem.n.Data, elem.label)
} }
case xml.EndElement: case xml.EndElement:
if elem == nil { if elem == nil {
log.Debug("no element, probably bad xml") log.Debug("no element, probably bad xml")
continue continue
} }
log.Debug("end element %v", elem.label) log.Debugf("end element %v", elem.label)
elem.state = "finished" elem.state = "finished"
// And add it to its parent list // And add it to its parent list
if elem.parent != nil { if elem.parent != nil {
@ -326,10 +326,10 @@ func (dec *xmlDecoder) decodeXML(root *xmlNode) error {
applyFootComment(elem, commentStr) applyFootComment(elem, commentStr)
case "chardata": case "chardata":
log.Debug("got a line comment for (%v) %v: [%v]", elem.state, elem.label, commentStr) log.Debugf("got a line comment for (%v) %v: [%v]", elem.state, elem.label, commentStr)
elem.n.LineComment = joinComments([]string{elem.n.LineComment, commentStr}, " ") elem.n.LineComment = joinComments([]string{elem.n.LineComment, commentStr}, " ")
default: default:
log.Debug("got a head comment for (%v) %v: [%v]", elem.state, elem.label, commentStr) log.Debugf("got a head comment for (%v) %v: [%v]", elem.state, elem.label, commentStr)
elem.n.HeadComment = joinComments([]string{elem.n.HeadComment, commentStr}, " ") elem.n.HeadComment = joinComments([]string{elem.n.HeadComment, commentStr}, " ")
} }
@ -354,7 +354,7 @@ func applyFootComment(elem *element, commentStr string) {
if len(elem.n.Children) > 0 { if len(elem.n.Children) > 0 {
lastChildIndex := len(elem.n.Children) - 1 lastChildIndex := len(elem.n.Children) - 1
childKv := elem.n.Children[lastChildIndex] childKv := elem.n.Children[lastChildIndex]
log.Debug("got a foot comment, putting on last child for %v: [%v]", childKv.K, commentStr) log.Debugf("got a foot comment, putting on last child for %v: [%v]", childKv.K, commentStr)
// if it's an array of scalars, put the foot comment on the scalar itself // if it's an array of scalars, put the foot comment on the scalar itself
if len(childKv.V) > 0 && len(childKv.V[0].Children) == 0 { if len(childKv.V) > 0 && len(childKv.V[0].Children) == 0 {
nodeToUpdate := childKv.V[len(childKv.V)-1] nodeToUpdate := childKv.V[len(childKv.V)-1]
@ -363,7 +363,7 @@ func applyFootComment(elem *element, commentStr string) {
childKv.FootComment = joinComments([]string{elem.n.FootComment, commentStr}, " ") childKv.FootComment = joinComments([]string{elem.n.FootComment, commentStr}, " ")
} }
} else { } else {
log.Debug("got a foot comment for %v: [%v]", elem.label, commentStr) log.Debugf("got a foot comment for %v: [%v]", elem.label, commentStr)
elem.n.FootComment = joinComments([]string{elem.n.FootComment, commentStr}, " ") elem.n.FootComment = joinComments([]string{elem.n.FootComment, commentStr}, " ")
} }
} }

View File

@ -32,7 +32,7 @@ func (ke *kyamlEncoder) PrintLeadingContent(writer io.Writer, content string) er
} }
func (ke *kyamlEncoder) Encode(writer io.Writer, node *CandidateNode) error { func (ke *kyamlEncoder) Encode(writer io.Writer, node *CandidateNode) error {
log.Debug("encoderKYaml - going to print %v", NodeToString(node)) log.Debugf("encoderKYaml - going to print %v", NodeToString(node))
if node.Kind == ScalarNode && ke.prefs.UnwrapScalar { if node.Kind == ScalarNode && ke.prefs.UnwrapScalar {
return writeString(writer, node.Value+"\n") return writeString(writer, node.Value+"\n")
} }

View File

@ -59,7 +59,7 @@ func (e *xmlEncoder) Encode(writer io.Writer, node *CandidateNode) error {
return err return err
} }
if _, err := e.writer.Write([]byte("\n")); err != nil { if _, err := e.writer.Write([]byte("\n")); err != nil {
log.Warning("Unable to write newline, skipping: %w", err) log.Warningf("Unable to write newline, skipping: %v", err)
} }
} }
} }
@ -131,7 +131,7 @@ func (e *xmlEncoder) encodeTopLevelMap(encoder *xml.Encoder, node *CandidateNode
return err return err
} }
if _, err := e.writer.Write([]byte("\n")); err != nil { if _, err := e.writer.Write([]byte("\n")); err != nil {
log.Warning("Unable to write newline, skipping: %w", err) log.Warningf("Unable to write newline, skipping: %v", err)
} }
} else if key.Value == e.prefs.DirectiveName { } else if key.Value == e.prefs.DirectiveName {
var directive xml.Directive = []byte(value.Value) var directive xml.Directive = []byte(value.Value)
@ -139,7 +139,7 @@ func (e *xmlEncoder) encodeTopLevelMap(encoder *xml.Encoder, node *CandidateNode
return err return err
} }
if _, err := e.writer.Write([]byte("\n")); err != nil { if _, err := e.writer.Write([]byte("\n")); err != nil {
log.Warning("Unable to write newline, skipping: %w", err) log.Warningf("Unable to write newline, skipping: %v", err)
} }
} else { } else {

View File

@ -29,7 +29,7 @@ func (ye *yamlEncoder) PrintLeadingContent(writer io.Writer, content string) err
} }
func (ye *yamlEncoder) Encode(writer io.Writer, node *CandidateNode) error { func (ye *yamlEncoder) Encode(writer io.Writer, node *CandidateNode) error {
log.Debug("encoderYaml - going to print %v", NodeToString(node)) log.Debugf("encoderYaml - going to print %v", NodeToString(node))
// Detect line ending style from LeadingContent // Detect line ending style from LeadingContent
lineEnding := "\n" lineEnding := "\n"
if strings.Contains(node.LeadingContent, "\r\n") { if strings.Contains(node.LeadingContent, "\r\n") {

View File

@ -26,7 +26,7 @@ func newExpressionParser() ExpressionParserInterface {
} }
func (p *expressionParserImpl) ParseExpression(expression string) (*ExpressionNode, error) { func (p *expressionParserImpl) ParseExpression(expression string) (*ExpressionNode, error) {
log.Debug("Parsing expression: [%v]", expression) log.Debugf("Parsing expression: [%v]", expression)
tokens, err := p.pathTokeniser.Tokenise(expression) tokens, err := p.pathTokeniser.Tokenise(expression)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -95,6 +95,7 @@ func TestParserSingleOperation(t *testing.T) {
test.AssertResultComplex(t, nil, err) test.AssertResultComplex(t, nil, err)
if result == nil { if result == nil {
t.Fatal("Expected non-nil result for single operation") t.Fatal("Expected non-nil result for single operation")
return
} }
if result.Operation == nil { if result.Operation == nil {
t.Fatal("Expected operation to be set") t.Fatal("Expected operation to be set")

View File

@ -3,8 +3,7 @@ package yqlib
import ( import (
"errors" "errors"
"fmt" "fmt"
"log/slog"
logging "gopkg.in/op/go-logging.v1"
) )
type expressionPostFixer interface { type expressionPostFixer interface {
@ -134,7 +133,7 @@ func (p *expressionPostFixerImpl) ConvertToPostfix(infixTokens []*token) ([]*Ope
return nil, fmt.Errorf("bad expression - probably missing close bracket on %v", opStack[len(opStack)-1].toString(false)) return nil, fmt.Errorf("bad expression - probably missing close bracket on %v", opStack[len(opStack)-1].toString(false))
} }
if log.IsEnabledFor(logging.DEBUG) { if log.IsEnabledFor(slog.LevelDebug) {
log.Debugf("PostFix Result:") log.Debugf("PostFix Result:")
for _, currentToken := range result { for _, currentToken := range result {
log.Debugf("> %v", currentToken.toString()) log.Debugf("> %v", currentToken.toString())

View File

@ -30,7 +30,7 @@ func tryRenameFile(from string, to string) error {
} }
func tryRemoveTempFile(filename string) { func tryRemoveTempFile(filename string) {
log.Debug("Removing temp file: %v", filename) log.Debugf("Removing temp file: %v", filename)
removeErr := os.Remove(filename) removeErr := os.Remove(filename)
if removeErr != nil { if removeErr != nil {
log.Errorf("Failed to remove temp file: %v", filename) log.Errorf("Failed to remove temp file: %v", filename)
@ -68,8 +68,7 @@ func SafelyCloseReader(reader io.Reader) {
func safelyCloseFile(file *os.File) { func safelyCloseFile(file *os.File) {
err := file.Close() err := file.Close()
if err != nil { if err != nil {
log.Error("Error closing file!") log.Errorf("Error closing file %v: %v", file.Name(), err)
log.Error(err.Error())
} }
} }

View File

@ -58,7 +58,7 @@ func (f *frontMatterHandlerImpl) Split() error {
return err return err
} }
f.yamlFrontMatterFilename = yamlTempFile.Name() f.yamlFrontMatterFilename = yamlTempFile.Name()
log.Debug("yamlTempFile: %v", yamlTempFile.Name()) log.Debugf("yamlTempFile: %v", yamlTempFile.Name())
lineCount := 0 lineCount := 0

View File

@ -108,6 +108,55 @@ yaml: doc
fmHandler.CleanUp() fmHandler.CleanUp()
} }
func TestFrontMatterFilenamePreserved(t *testing.T) {
// Regression test for https://github.com/mikefarah/yq/issues/2538
// When using --front-matter, the filename operator should return
// the original filename, not the path to the temporary file.
file := createTestFile(`---
name: john
---
Some content
`)
originalFilename := "/path/to/original/file.md"
fmHandler := NewFrontMatterHandler(file)
err := fmHandler.Split()
if err != nil {
panic(err)
}
tempFilename := fmHandler.GetYamlFrontMatterFilename()
// Register the alias (as the command code does)
SetFilenameAlias(tempFilename, originalFilename)
defer ClearFilenameAliases()
// Verify resolveFilename returns the original name
resolved := resolveFilename(tempFilename)
test.AssertResult(t, originalFilename, resolved)
// Read documents using the temp file, verify they get the original filename
reader, err := readStream(tempFilename)
if err != nil {
panic(err)
}
decoder := NewYamlDecoder(ConfiguredYamlPreferences)
docs, err := readDocuments(reader, tempFilename, 0, decoder)
if err != nil {
panic(err)
}
if docs.Len() == 0 {
t.Fatal("expected at least one document")
}
firstDoc := docs.Front().Value.(*CandidateNode)
test.AssertResult(t, originalFilename, firstDoc.filename)
tryRemoveTempFile(file)
fmHandler.CleanUp()
}
func TestFrontMatterSplitWithArray(t *testing.T) { func TestFrontMatterSplitWithArray(t *testing.T) {
file := createTestFile(`[1,2,3] file := createTestFile(`[1,2,3]
--- ---

View File

@ -105,7 +105,7 @@ func handleToken(tokens []*token, index int, postProcessedTokens []*token) (toke
skipNextToken = false skipNextToken = false
currentToken := tokens[index] currentToken := tokens[index]
log.Debug("processing %v", currentToken.toString(true)) log.Debugf("processing %v", currentToken.toString(true))
if currentToken.TokenType == traverseArrayCollect { if currentToken.TokenType == traverseArrayCollect {
// `.[exp]`` works by creating a traversal array of [self, exp] and piping that into the traverse array operator // `.[exp]`` works by creating a traversal array of [self, exp] and piping that into the traverse array operator

View File

@ -283,7 +283,7 @@ func pathToken(wrapped bool) yqAction {
if wrapped { if wrapped {
value = unwrap(value) value = unwrap(value)
} }
log.Debug("PathToken %v", value) log.Debugf("PathToken %v", value)
op := &Operation{OperationType: traversePathOpType, Value: value, StringValue: value, Preferences: prefs} op := &Operation{OperationType: traversePathOpType, Value: value, StringValue: value, Preferences: prefs}
return &token{TokenType: operationToken, Operation: op, CheckForPostTraverse: true}, nil return &token{TokenType: operationToken, Operation: op, CheckForPostTraverse: true}, nil
} }
@ -336,7 +336,7 @@ func flattenWithDepth() yqAction {
func assignAllCommentsOp(updateAssign bool) yqAction { func assignAllCommentsOp(updateAssign bool) yqAction {
return func(rawToken lexer.Token) (*token, error) { return func(rawToken lexer.Token) (*token, error) {
log.Debug("assignAllCommentsOp %v", rawToken.Value) log.Debugf("assignAllCommentsOp %v", rawToken.Value)
value := rawToken.Value value := rawToken.Value
op := &Operation{ op := &Operation{
OperationType: assignCommentOpType, OperationType: assignCommentOpType,
@ -351,7 +351,7 @@ func assignAllCommentsOp(updateAssign bool) yqAction {
func assignOpToken(updateAssign bool) yqAction { func assignOpToken(updateAssign bool) yqAction {
return func(rawToken lexer.Token) (*token, error) { return func(rawToken lexer.Token) (*token, error) {
log.Debug("assignOpToken %v", rawToken.Value) log.Debugf("assignOpToken %v", rawToken.Value)
value := rawToken.Value value := rawToken.Value
prefs := assignPreferences{DontOverWriteAnchor: true} prefs := assignPreferences{DontOverWriteAnchor: true}
if strings.Contains(value, "c") { if strings.Contains(value, "c") {
@ -376,9 +376,9 @@ func nullValue() yqAction {
func stringValue() yqAction { func stringValue() yqAction {
return func(rawToken lexer.Token) (*token, error) { return func(rawToken lexer.Token) (*token, error) {
log.Debug("rawTokenvalue: %v", rawToken.Value) log.Debugf("rawTokenvalue: %v", rawToken.Value)
value := unwrap(rawToken.Value) value := unwrap(rawToken.Value)
log.Debug("unwrapped: %v", value) log.Debugf("unwrapped: %v", value)
value = processEscapeCharacters(value) value = processEscapeCharacters(value)
return &token{TokenType: operationToken, Operation: &Operation{ return &token{TokenType: operationToken, Operation: &Operation{
OperationType: stringInterpolationOpType, OperationType: stringInterpolationOpType,

View File

@ -4,11 +4,10 @@ package yqlib
import ( import (
"container/list" "container/list"
"fmt" "fmt"
"log/slog"
"math" "math"
"strconv" "strconv"
"strings" "strings"
logging "gopkg.in/op/go-logging.v1"
) )
var ExpressionParser ExpressionParserInterface var ExpressionParser ExpressionParserInterface
@ -19,12 +18,12 @@ func InitExpressionParser() {
} }
} }
var log = logging.MustGetLogger("yq-lib") var log = newLogger()
var PrettyPrintExp = `(... | (select(tag != "!!str"), select(tag == "!!str") | select(test("(?i)^(y|yes|n|no|on|off)$") | not)) ) style=""` var PrettyPrintExp = `(... | (select(tag != "!!str"), select(tag == "!!str") | select(test("(?i)^(y|yes|n|no|on|off)$") | not)) ) style=""`
// GetLogger returns the yq logger instance. // GetLogger returns the yq logger instance.
func GetLogger() *logging.Logger { func GetLogger() *Logger {
return log return log
} }
@ -251,7 +250,7 @@ func processEscapeCharacters(original string) string {
value := result.String() value := result.String()
if value != original { if value != original {
log.Debug("processEscapeCharacters from [%v] to [%v]", original, value) log.Debugf("processEscapeCharacters from [%v] to [%v]", original, value)
} }
return value return value
} }
@ -274,7 +273,7 @@ func footComment(node *CandidateNode) string {
// use for debugging only // use for debugging only
func NodesToString(collection *list.List) string { func NodesToString(collection *list.List) string {
if !log.IsEnabledFor(logging.DEBUG) { if !log.IsEnabledFor(slog.LevelDebug) {
return "" return ""
} }
@ -286,7 +285,7 @@ func NodesToString(collection *list.List) string {
} }
func NodeToString(node *CandidateNode) string { func NodeToString(node *CandidateNode) string {
if !log.IsEnabledFor(logging.DEBUG) { if !log.IsEnabledFor(slog.LevelDebug) {
return "" return ""
} }
if node == nil { if node == nil {
@ -304,7 +303,7 @@ func NodeToString(node *CandidateNode) string {
} }
func NodeContentToString(node *CandidateNode, depth int) string { func NodeContentToString(node *CandidateNode, depth int) string {
if !log.IsEnabledFor(logging.DEBUG) { if !log.IsEnabledFor(slog.LevelDebug) {
return "" return ""
} }
var sb strings.Builder var sb strings.Builder

77
pkg/yqlib/logger.go Normal file
View File

@ -0,0 +1,77 @@
package yqlib
import (
"fmt"
"log/slog"
"os"
)
// Logger wraps log/slog providing a printf-style interface used throughout yq.
type Logger struct {
levelVar slog.LevelVar
slogger *slog.Logger
}
func newLogger() *Logger {
l := &Logger{}
l.levelVar.Set(slog.LevelWarn)
handler := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: &l.levelVar})
l.slogger = slog.New(handler)
return l
}
// SetLevel sets the minimum log level.
func (l *Logger) SetLevel(level slog.Level) {
l.levelVar.Set(level)
}
// GetLevel returns the current log level.
func (l *Logger) GetLevel() slog.Level {
return l.levelVar.Level()
}
// IsEnabledFor returns true if the given level is enabled.
func (l *Logger) IsEnabledFor(level slog.Level) bool {
return l.levelVar.Level() <= level
}
// SetSlogger replaces the underlying slog.Logger (e.g. to configure output format).
func (l *Logger) SetSlogger(logger *slog.Logger) {
l.slogger = logger
}
func (l *Logger) Debug(msg string) {
if l.IsEnabledFor(slog.LevelDebug) {
l.slogger.Debug(msg)
}
}
func (l *Logger) Debugf(format string, args ...interface{}) {
if l.IsEnabledFor(slog.LevelDebug) {
l.slogger.Debug(fmt.Sprintf(format, args...))
}
}
func (l *Logger) Info(msg string) {
l.slogger.Info(msg)
}
func (l *Logger) Infof(format string, args ...interface{}) {
l.slogger.Info(fmt.Sprintf(format, args...))
}
func (l *Logger) Warning(msg string) {
l.slogger.Warn(msg)
}
func (l *Logger) Warningf(format string, args ...interface{}) {
l.slogger.Warn(fmt.Sprintf(format, args...))
}
func (l *Logger) Error(msg string) {
l.slogger.Error(msg)
}
func (l *Logger) Errorf(format string, args ...interface{}) {
l.slogger.Error(fmt.Sprintf(format, args...))
}

View File

@ -25,7 +25,7 @@ var valueToStringFunc = func(p *Operation) string {
} }
func createValueOperation(value interface{}, stringValue string) *Operation { func createValueOperation(value interface{}, stringValue string) *Operation {
log.Debug("creating value op for string %v", stringValue) log.Debugf("creating value op for string %v", stringValue)
var node = createScalarNode(value, stringValue) var node = createScalarNode(value, stringValue)
return &Operation{ return &Operation{

View File

@ -195,9 +195,9 @@ func addMaps(target *CandidateNode, lhsC *CandidateNode, rhsC *CandidateNode) {
for index := 0; index < len(rhs.Content); index = index + 2 { for index := 0; index < len(rhs.Content); index = index + 2 {
key := rhs.Content[index] key := rhs.Content[index]
value := rhs.Content[index+1] value := rhs.Content[index+1]
log.Debug("finding %v", key.Value) log.Debugf("finding %v", key.Value)
indexInLHS := findKeyInMap(target, key) indexInLHS := findKeyInMap(target, key)
log.Debug("indexInLhs %v", indexInLHS) log.Debugf("indexInLhs %v", indexInLHS)
if indexInLHS < 0 { if indexInLHS < 0 {
// not in there, append it // not in there, append it
target.AddKeyValueChild(key, value) target.AddKeyValueChild(key, value)

View File

@ -256,7 +256,7 @@ func explodeNode(node *CandidateNode, context Context) error {
node.Value = node.Alias.Value node.Value = node.Alias.Value
node.Alias = nil node.Alias = nil
} }
log.Debug("now I'm %v", NodeToString(node)) log.Debugf("now I'm %v", NodeToString(node))
return nil return nil
case MappingNode: case MappingNode:
// //check the map has an alias in it // //check the map has an alias in it
@ -304,7 +304,7 @@ func applyAlias(node *CandidateNode, alias *CandidateNode, aliasIndex int, newCo
if alias == nil { if alias == nil {
return nil return nil
} }
log.Debug("alias: %v", NodeToString(alias)) log.Debugf("alias: %v", NodeToString(alias))
if alias.Kind != MappingNode { if alias.Kind != MappingNode {
return fmt.Errorf("can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v", alias.Tag) return fmt.Errorf("can only use merge anchors with maps (!!map) or sequences (!!seq) of maps, but got sequence containing %v", alias.Tag)
} }

View File

@ -37,7 +37,7 @@ func assignUpdateOperator(d *dataTreeNavigator, context Context, expressionNode
prefs := getAssignPreferences(expressionNode.Operation.Preferences) prefs := getAssignPreferences(expressionNode.Operation.Preferences)
log.Debug("assignUpdateOperator prefs: %v", prefs) log.Debugf("assignUpdateOperator prefs: %v", prefs)
if !expressionNode.Operation.UpdateAssign { if !expressionNode.Operation.UpdateAssign {
// this works because we already ran against LHS with an editable context. // this works because we already ran against LHS with an editable context.

View File

@ -142,7 +142,7 @@ func notOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Cont
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode) candidate := el.Value.(*CandidateNode)
log.Debug("notOperation checking %v", candidate) log.Debugf("notOperation checking %v", candidate)
truthy := isTruthyNode(candidate) truthy := isTruthyNode(candidate)
result := createBooleanCandidate(candidate, !truthy) result := createBooleanCandidate(candidate, !truthy)
results.PushBack(result) results.PushBack(result)

View File

@ -80,7 +80,7 @@ func formatDateTime(d *dataTreeNavigator, context Context, expressionNode *Expre
node, errorReading := parseSnippet(formattedTimeStr) node, errorReading := parseSnippet(formattedTimeStr)
if errorReading != nil { if errorReading != nil {
log.Debugf("could not parse %v - lets just leave it as a string: %w", formattedTimeStr, errorReading) log.Debugf("could not parse %v - lets just leave it as a string: %v", formattedTimeStr, errorReading)
node = &CandidateNode{ node = &CandidateNode{
Kind: ScalarNode, Kind: ScalarNode,
Tag: "!!str", Tag: "!!str",

View File

@ -45,7 +45,7 @@ func removeFromContext(context Context, candidate *CandidateNode) (Context, erro
if nodeInContext != candidate { if nodeInContext != candidate {
newResults.PushBack(nodeInContext) newResults.PushBack(nodeInContext)
} else { } else {
log.Info("Need to delete this %v", NodeToString(nodeInContext)) log.Infof("Need to delete this %v", NodeToString(nodeInContext))
} }
} }
return context.ChildContext(newResults), nil return context.ChildContext(newResults), nil

View File

@ -33,7 +33,7 @@ func configureEncoder(format *Format, indent int) Encoder {
func encodeToString(candidate *CandidateNode, prefs encoderPreferences) (string, error) { func encodeToString(candidate *CandidateNode, prefs encoderPreferences) (string, error) {
var output bytes.Buffer var output bytes.Buffer
log.Debug("printing with indent: %v", prefs.indent) log.Debugf("printing with indent: %v", prefs.indent)
encoder := configureEncoder(prefs.format, prefs.indent) encoder := configureEncoder(prefs.format, prefs.indent)
if encoder == nil { if encoder == nil {

View File

@ -157,10 +157,10 @@ func withEntriesOperator(d *dataTreeNavigator, context Context, expressionNode *
if err != nil { if err != nil {
return Context{}, err return Context{}, err
} }
log.Debug("candidate %v", NodeToString(candidate)) log.Debugf("candidate %v", NodeToString(candidate))
log.Debug("candidate leading content: %v", candidate.LeadingContent) log.Debugf("candidate leading content: %v", candidate.LeadingContent)
collected.LeadingContent = candidate.LeadingContent collected.LeadingContent = candidate.LeadingContent
log.Debug("candidate FootComment: [%v]", candidate.FootComment) log.Debugf("candidate FootComment: [%v]", candidate.FootComment)
collected.HeadComment = candidate.HeadComment collected.HeadComment = candidate.HeadComment
collected.FootComment = candidate.FootComment collected.FootComment = candidate.FootComment

View File

@ -21,7 +21,7 @@ func envOperator(_ *dataTreeNavigator, context Context, expressionNode *Expressi
return Context{}, fmt.Errorf("env operations have been disabled") return Context{}, fmt.Errorf("env operations have been disabled")
} }
envName := expressionNode.Operation.CandidateNode.Value envName := expressionNode.Operation.CandidateNode.Value
log.Debug("EnvOperator, env name:", envName) log.Debugf("EnvOperator, env name: %v", envName)
rawValue := os.Getenv(envName) rawValue := os.Getenv(envName)
@ -49,9 +49,9 @@ func envOperator(_ *dataTreeNavigator, context Context, expressionNode *Expressi
} }
} }
log.Debug("ENV tag", node.Tag) log.Debugf("ENV tag: %v", node.Tag)
log.Debug("ENV value", node.Value) log.Debugf("ENV value: %v", node.Value)
log.Debug("ENV Kind", node.Kind) log.Debugf("ENV Kind: %v", node.Kind)
return context.SingleChildContext(node), nil return context.SingleChildContext(node), nil
} }
@ -78,7 +78,7 @@ func envsubstOperator(_ *dataTreeNavigator, context Context, expressionNode *Exp
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {
node := el.Value.(*CandidateNode) node := el.Value.(*CandidateNode)
if node.Tag != "!!str" { if node.Tag != "!!str" {
log.Warning("EnvSubstOperator, env name:", node.Tag, node.Value) log.Warningf("EnvSubstOperator, env name: %v %v", node.Tag, node.Value)
return Context{}, fmt.Errorf("cannot substitute with %v, can only substitute strings. Hint: Most often you'll want to use '|=' over '=' for this operation", node.Tag) return Context{}, fmt.Errorf("cannot substitute with %v, can only substitute strings. Hint: Most often you'll want to use '|=' over '=' for this operation", node.Tag)
} }

View File

@ -47,8 +47,8 @@ func mapOperator(d *dataTreeNavigator, context Context, expressionNode *Expressi
} }
result, err := d.GetMatchingNodes(splatted, expressionNode.RHS) result, err := d.GetMatchingNodes(splatted, expressionNode.RHS)
log.Debug("expressionNode.Rhs %v", expressionNode.RHS.Operation.OperationType) log.Debugf("expressionNode.Rhs %v", expressionNode.RHS.Operation.OperationType)
log.Debug("result %v", result) log.Debugf("result %v", result)
if err != nil { if err != nil {
return Context{}, err return Context{}, err
} }

View File

@ -19,8 +19,8 @@ func getSliceNumber(d *dataTreeNavigator, context Context, node *CandidateNode,
func sliceArrayOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func sliceArrayOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debug("slice array operator!") log.Debug("slice array operator!")
log.Debug("lhs: %v", expressionNode.LHS.Operation.toString()) log.Debugf("lhs: %v", expressionNode.LHS.Operation.toString())
log.Debug("rhs: %v", expressionNode.RHS.Operation.toString()) log.Debugf("rhs: %v", expressionNode.RHS.Operation.toString())
results := list.New() results := list.New()
@ -49,7 +49,7 @@ func sliceArrayOperator(d *dataTreeNavigator, context Context, expressionNode *E
relativeSecondNumber = len(lhsNode.Content) relativeSecondNumber = len(lhsNode.Content)
} }
log.Debug("calculateIndicesToTraverse: slice from %v to %v", relativeFirstNumber, relativeSecondNumber) log.Debugf("calculateIndicesToTraverse: slice from %v to %v", relativeFirstNumber, relativeSecondNumber)
var newResults []*CandidateNode var newResults []*CandidateNode
for i := relativeFirstNumber; i < relativeSecondNumber; i++ { for i := relativeFirstNumber; i < relativeSecondNumber; i++ {

View File

@ -142,12 +142,12 @@ func (a sortableNodeArray) compare(lhs *CandidateNode, rhs *CandidateNode, dateT
} else if isDateTime { } else if isDateTime {
lhsTime, err := parseDateTime(layout, lhs.Value) lhsTime, err := parseDateTime(layout, lhs.Value)
if err != nil { if err != nil {
log.Warningf("Could not parse time %v with layout %v for sort, sorting by string instead: %w", lhs.Value, layout, err) log.Warningf("Could not parse time %v with layout %v for sort, sorting by string instead: %v", lhs.Value, layout, err)
return strings.Compare(lhs.Value, rhs.Value) return strings.Compare(lhs.Value, rhs.Value)
} }
rhsTime, err := parseDateTime(layout, rhs.Value) rhsTime, err := parseDateTime(layout, rhs.Value)
if err != nil { if err != nil {
log.Warningf("Could not parse time %v with layout %v for sort, sorting by string instead: %w", rhs.Value, layout, err) log.Warningf("Could not parse time %v with layout %v for sort, sorting by string instead: %v", rhs.Value, layout, err)
return strings.Compare(lhs.Value, rhs.Value) return strings.Compare(lhs.Value, rhs.Value)
} }
if lhsTime.Equal(rhsTime) { if lhsTime.Equal(rhsTime) {

View File

@ -220,7 +220,7 @@ func getSubstituteParameters(d *dataTreeNavigator, block *ExpressionNode, contex
regEx = regExNodes.MatchingNodes.Front().Value.(*CandidateNode).Value regEx = regExNodes.MatchingNodes.Front().Value.(*CandidateNode).Value
} }
log.Debug("regEx %v", regEx) log.Debugf("regEx %v", regEx)
replacementNodes, err := d.GetMatchingNodes(context, block.RHS) replacementNodes, err := d.GetMatchingNodes(context, block.RHS)
if err != nil { if err != nil {
@ -318,7 +318,7 @@ func getMatches(matchPrefs matchPreferences, regEx *regexp.Regexp, value string)
allIndices = [][]int{regEx.FindStringSubmatchIndex(value)} allIndices = [][]int{regEx.FindStringSubmatchIndex(value)}
} }
log.Debug("allMatches, %v", allMatches) log.Debugf("allMatches, %v", allMatches)
return allMatches, allIndices return allMatches, allIndices
} }
@ -423,7 +423,7 @@ func extractMatchArguments(d *dataTreeNavigator, context Context, expressionNode
if regExNodes.MatchingNodes.Front() != nil { if regExNodes.MatchingNodes.Front() != nil {
regExStr = regExNodes.MatchingNodes.Front().Value.(*CandidateNode).Value regExStr = regExNodes.MatchingNodes.Front().Value.(*CandidateNode).Value
} }
log.Debug("regEx %v", regExStr) log.Debugf("regEx %v", regExStr)
regEx, err := regexp.Compile(regExStr) regEx, err := regexp.Compile(regExStr)
return regEx, matchPrefs, err return regEx, matchPrefs, err
} }
@ -564,7 +564,7 @@ func split(value string, spltStr string) (Kind, string, []*CandidateNode) {
var contents []*CandidateNode var contents []*CandidateNode
if value != "" { if value != "" {
log.Debug("going to spltStr[%v]", spltStr) log.Debugf("going to spltStr[%v]", spltStr)
var newStrings = strings.Split(value, spltStr) var newStrings = strings.Split(value, spltStr)
contents = make([]*CandidateNode, len(newStrings)) contents = make([]*CandidateNode, len(newStrings))

View File

@ -26,7 +26,7 @@ func parseStyle(customStyle string) (Style, error) {
func assignStyleOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func assignStyleOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("AssignStyleOperator: %v") log.Debugf("AssignStyleOperator")
var style Style var style Style
if !expressionNode.Operation.UpdateAssign { if !expressionNode.Operation.UpdateAssign {
rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS) rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)

View File

@ -6,7 +6,7 @@ import (
func assignTagOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func assignTagOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("AssignTagOperator: %v") log.Debugf("AssignTagOperator")
tag := "" tag := ""
if !expressionNode.Operation.UpdateAssign { if !expressionNode.Operation.UpdateAssign {

View File

@ -37,7 +37,7 @@ func traversePathOperator(_ *dataTreeNavigator, context Context, expressionNode
} }
func traverse(context Context, matchingNode *CandidateNode, operation *Operation) (*list.List, error) { func traverse(context Context, matchingNode *CandidateNode, operation *Operation) (*list.List, error) {
log.Debug("Traversing %v", NodeToString(matchingNode)) log.Debugf("Traversing %v", NodeToString(matchingNode))
if matchingNode.Tag == "!!null" && operation.Value != "[]" && !context.DontAutoCreate { if matchingNode.Tag == "!!null" && operation.Value != "[]" && !context.DontAutoCreate {
log.Debugf("Guessing kind") log.Debugf("Guessing kind")
@ -55,11 +55,11 @@ func traverse(context Context, matchingNode *CandidateNode, operation *Operation
switch matchingNode.Kind { switch matchingNode.Kind {
case MappingNode: case MappingNode:
log.Debug("its a map with %v entries", len(matchingNode.Content)/2) log.Debugf("its a map with %v entries", len(matchingNode.Content)/2)
return traverseMap(context, matchingNode, createStringScalarNode(operation.StringValue), operation.Preferences.(traversePreferences), false) return traverseMap(context, matchingNode, createStringScalarNode(operation.StringValue), operation.Preferences.(traversePreferences), false)
case SequenceNode: case SequenceNode:
log.Debug("its a sequence of %v things!", len(matchingNode.Content)) log.Debugf("its a sequence of %v things!", len(matchingNode.Content))
return traverseArray(matchingNode, operation, operation.Preferences.(traversePreferences)) return traverseArray(matchingNode, operation, operation.Preferences.(traversePreferences))
case AliasNode: case AliasNode:
@ -158,7 +158,7 @@ func traverseMapWithIndices(context Context, candidate *CandidateNode, indices [
var matchingNodeMap = list.New() var matchingNodeMap = list.New()
for _, indexNode := range indices { for _, indexNode := range indices {
log.Debug("traverseMapWithIndices: %v", indexNode.Value) log.Debugf("traverseMapWithIndices: %v", indexNode.Value)
newNodes, err := traverseMap(context, candidate, indexNode, prefs, false) newNodes, err := traverseMap(context, candidate, indexNode, prefs, false)
if err != nil { if err != nil {
return nil, err return nil, err
@ -183,7 +183,7 @@ func traverseArrayWithIndices(node *CandidateNode, indices []*CandidateNode, pre
} }
for _, indexNode := range indices { for _, indexNode := range indices {
log.Debug("traverseArrayWithIndices: '%v'", indexNode.Value) log.Debugf("traverseArrayWithIndices: '%v'", indexNode.Value)
index, err := parseInt(indexNode.Value) index, err := parseInt(indexNode.Value)
if err != nil && prefs.OptionalTraverse { if err != nil && prefs.OptionalTraverse {
continue continue
@ -366,7 +366,7 @@ func traverseMergeAnchor(newMatches *orderedmap.OrderedMap, merge *CandidateNode
} }
func traverseArray(candidate *CandidateNode, operation *Operation, prefs traversePreferences) (*list.List, error) { func traverseArray(candidate *CandidateNode, operation *Operation, prefs traversePreferences) (*list.List, error) {
log.Debug("operation Value %v", operation.Value) log.Debugf("operation Value %v", operation.Value)
indices := []*CandidateNode{{Value: operation.StringValue}} indices := []*CandidateNode{{Value: operation.StringValue}}
return traverseArrayWithIndices(candidate, indices, prefs) return traverseArrayWithIndices(candidate, indices, prefs)
} }

View File

@ -4,21 +4,21 @@ import "container/list"
func unionOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func unionOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debug("unionOperator--") log.Debug("unionOperator--")
log.Debug("unionOperator: context: %v", NodesToString(context.MatchingNodes)) log.Debugf("unionOperator: context: %v", NodesToString(context.MatchingNodes))
lhs, err := d.GetMatchingNodes(context, expressionNode.LHS) lhs, err := d.GetMatchingNodes(context, expressionNode.LHS)
if err != nil { if err != nil {
return Context{}, err return Context{}, err
} }
log.Debug("unionOperator: lhs: %v", NodesToString(lhs.MatchingNodes)) log.Debugf("unionOperator: lhs: %v", NodesToString(lhs.MatchingNodes))
log.Debug("unionOperator: rhs input: %v", NodesToString(context.MatchingNodes)) log.Debugf("unionOperator: rhs input: %v", NodesToString(context.MatchingNodes))
log.Debug("unionOperator: rhs: %v", expressionNode.RHS.Operation.toString()) log.Debugf("unionOperator: rhs: %v", expressionNode.RHS.Operation.toString())
rhs, err := d.GetMatchingNodes(context, expressionNode.RHS) rhs, err := d.GetMatchingNodes(context, expressionNode.RHS)
if err != nil { if err != nil {
return Context{}, err return Context{}, err
} }
log.Debug("unionOperator: lhs: %v", lhs.ToString()) log.Debugf("unionOperator: lhs: %v", lhs.ToString())
log.Debug("unionOperator: rhs: %v", rhs.ToString()) log.Debugf("unionOperator: rhs: %v", rhs.ToString())
results := lhs.ChildContext(list.New()) results := lhs.ChildContext(list.New())
for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() { for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() {
@ -33,11 +33,11 @@ func unionOperator(d *dataTreeNavigator, context Context, expressionNode *Expres
for el := rhs.MatchingNodes.Front(); el != nil; el = el.Next() { for el := rhs.MatchingNodes.Front(); el != nil; el = el.Next() {
node := el.Value.(*CandidateNode) node := el.Value.(*CandidateNode)
log.Debug("union operator rhs: processing %v", NodeToString(node)) log.Debugf("union operator rhs: processing %v", NodeToString(node))
results.MatchingNodes.PushBack(node) results.MatchingNodes.PushBack(node)
} }
} }
log.Debug("union operator: all together: %v", results.ToString()) log.Debugf("union operator: all together: %v", results.ToString())
return results, nil return results, nil
} }

View File

@ -7,7 +7,7 @@ func referenceOperator(_ *dataTreeNavigator, context Context, expressionNode *Ex
} }
func valueOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func valueOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debug("value = %v", expressionNode.Operation.CandidateNode.Value) log.Debugf("value = %v", expressionNode.Operation.CandidateNode.Value)
if context.MatchingNodes.Len() == 0 { if context.MatchingNodes.Len() == 0 {
clone := expressionNode.Operation.CandidateNode.Copy() clone := expressionNode.Operation.CandidateNode.Copy()
return context.SingleChildContext(clone), nil return context.SingleChildContext(clone), nil

View File

@ -7,7 +7,7 @@ import (
func getVariableOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func getVariableOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
variableName := expressionNode.Operation.StringValue variableName := expressionNode.Operation.StringValue
log.Debug("getVariableOperator %v", variableName) log.Debugf("getVariableOperator %v", variableName)
result := context.GetVariable(variableName) result := context.GetVariable(variableName)
if result == nil { if result == nil {
result = list.New() result = list.New()
@ -67,7 +67,7 @@ func variableLoopSingleChild(d *dataTreeNavigator, context Context, originalExp
// now we loop over lhs, set variable to each result and calculate originalExp.Rhs // now we loop over lhs, set variable to each result and calculate originalExp.Rhs
for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() { for el := lhs.MatchingNodes.Front(); el != nil; el = el.Next() {
log.Debug("PROCESSING VARIABLE: ", NodeToString(el.Value.(*CandidateNode))) log.Debugf("PROCESSING VARIABLE: %v", NodeToString(el.Value.(*CandidateNode)))
var variableValue = list.New() var variableValue = list.New()
if prefs.IsReference { if prefs.IsReference {
variableValue.PushBack(el.Value) variableValue.PushBack(el.Value)
@ -83,7 +83,7 @@ func variableLoopSingleChild(d *dataTreeNavigator, context Context, originalExp
if err != nil { if err != nil {
return Context{}, err return Context{}, err
} }
log.Debug("PROCESSING VARIABLE DONE, got back: ", rhs.MatchingNodes.Len()) log.Debugf("PROCESSING VARIABLE DONE, got back: %v", rhs.MatchingNodes.Len())
results.PushBackList(rhs.MatchingNodes) results.PushBackList(rhs.MatchingNodes)
} }

View File

@ -3,9 +3,9 @@ package yqlib
import ( import (
"container/list" "container/list"
"fmt" "fmt"
"log/slog"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
logging "gopkg.in/op/go-logging.v1"
) )
type operatorHandler func(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) type operatorHandler func(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error)
@ -88,7 +88,7 @@ func resultsForRHS(d *dataTreeNavigator, context Context, lhsCandidate *Candidat
for rightEl := rhs.MatchingNodes.Front(); rightEl != nil; rightEl = rightEl.Next() { for rightEl := rhs.MatchingNodes.Front(); rightEl != nil; rightEl = rightEl.Next() {
rhsCandidate := rightEl.Value.(*CandidateNode) rhsCandidate := rightEl.Value.(*CandidateNode)
if !log.IsEnabledFor(logging.DEBUG) { if !log.IsEnabledFor(slog.LevelDebug) {
log.Debugf("Applying lhs: %v, rhsCandidate, %v", NodeToString(lhsCandidate), NodeToString(rhsCandidate)) log.Debugf("Applying lhs: %v, rhsCandidate, %v", NodeToString(lhsCandidate), NodeToString(rhsCandidate))
} }
resultCandidate, err := prefs.Calculation(d, context, lhsCandidate, rhsCandidate) resultCandidate, err := prefs.Calculation(d, context, lhsCandidate, rhsCandidate)

View File

@ -7,6 +7,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/fs" "io/fs"
"log/slog"
"os" "os"
"sort" "sort"
"strings" "strings"
@ -14,7 +15,6 @@ import (
"time" "time"
"github.com/mikefarah/yq/v4/test" "github.com/mikefarah/yq/v4/test"
logging "gopkg.in/op/go-logging.v1"
) )
type expressionScenario struct { type expressionScenario struct {
@ -38,9 +38,9 @@ var goccyTesting = false
var testingDecoder = NewYamlDecoder(ConfiguredYamlPreferences) var testingDecoder = NewYamlDecoder(ConfiguredYamlPreferences)
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
logging.SetLevel(logging.WARNING, "") GetLogger().SetLevel(slog.LevelWarn)
if os.Getenv("DEBUG") == "true" { if os.Getenv("DEBUG") == "true" {
logging.SetLevel(logging.DEBUG, "") GetLogger().SetLevel(slog.LevelDebug)
} }
ConfiguredYamlPreferences.ColorsEnabled = false ConfiguredYamlPreferences.ColorsEnabled = false
ConfiguredJSONPreferences.ColorsEnabled = false ConfiguredJSONPreferences.ColorsEnabled = false

View File

@ -70,7 +70,7 @@ func removeLastEOL(b *bytes.Buffer) {
} }
func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error { func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error {
log.Debug("PrintResults for %v matches", matchingNodes.Len()) log.Debugf("PrintResults for %v matches", matchingNodes.Len())
if matchingNodes.Len() == 0 { if matchingNodes.Len() == 0 {
log.Debug("no matching results, nothing to print") log.Debug("no matching results, nothing to print")
@ -97,8 +97,8 @@ func (p *resultsPrinter) PrintResults(matchingNodes *list.List) error {
for el := matchingNodes.Front(); el != nil; el = el.Next() { for el := matchingNodes.Front(); el != nil; el = el.Next() {
mappedDoc := el.Value.(*CandidateNode) mappedDoc := el.Value.(*CandidateNode)
log.Debug("print sep logic: p.firstTimePrinting: %v, previousDocIndex: %v", p.firstTimePrinting, p.previousDocIndex) log.Debugf("print sep logic: p.firstTimePrinting: %v, previousDocIndex: %v", p.firstTimePrinting, p.previousDocIndex)
log.Debug("%v", NodeToString(mappedDoc)) log.Debugf("%v", NodeToString(mappedDoc))
writer, errorWriting := p.printerWriter.GetWriter(mappedDoc) writer, errorWriting := p.printerWriter.GetWriter(mappedDoc)
if errorWriting != nil { if errorWriting != nil {
return errorWriting return errorWriting

View File

@ -76,6 +76,7 @@ func (s *streamEvaluator) EvaluateFiles(expression string, filenames []string, p
} }
func (s *streamEvaluator) Evaluate(filename string, reader io.Reader, node *ExpressionNode, printer Printer, decoder Decoder) (uint, error) { func (s *streamEvaluator) Evaluate(filename string, reader io.Reader, node *ExpressionNode, printer Printer, decoder Decoder) (uint, error) {
filename = resolveFilename(filename)
var currentIndex uint var currentIndex uint
err := decoder.Init(reader) err := decoder.Init(reader)

View File

@ -9,6 +9,29 @@ import (
"os" "os"
) )
// filenameAliases maps real file paths to display names.
// Used by front matter handling to preserve original filenames
// when the actual content is read from temporary files.
var filenameAliases = map[string]string{}
// SetFilenameAlias registers a display name for a file path so that
// the filename operator returns the original name instead of a temp path.
func SetFilenameAlias(realPath string, displayName string) {
filenameAliases[realPath] = displayName
}
// ClearFilenameAliases removes all filename aliases.
func ClearFilenameAliases() {
filenameAliases = map[string]string{}
}
func resolveFilename(filename string) string {
if alias, ok := filenameAliases[filename]; ok {
return alias
}
return filename
}
func readStream(filename string) (io.Reader, error) { func readStream(filename string) (io.Reader, error) {
var reader *bufio.Reader var reader *bufio.Reader
if filename == "-" { if filename == "-" {
@ -36,6 +59,7 @@ func ReadDocuments(reader io.Reader, decoder Decoder) (*list.List, error) {
} }
func readDocuments(reader io.Reader, filename string, fileIndex int, decoder Decoder) (*list.List, error) { func readDocuments(reader io.Reader, filename string, fileIndex int, decoder Decoder) (*list.List, error) {
filename = resolveFilename(filename)
err := decoder.Init(reader) err := decoder.Init(reader)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -38,13 +38,13 @@ func (w *writeInPlaceHandlerImpl) CreateTempFile() (*os.File, error) {
if err = changeOwner(info, file); err != nil { if err = changeOwner(info, file); err != nil {
return nil, err return nil, err
} }
log.Debug("WriteInPlaceHandler: writing to tempfile: %v", file.Name()) log.Debugf("WriteInPlaceHandler: writing to tempfile: %v", file.Name())
w.tempFile = file w.tempFile = file
return file, err return file, err
} }
func (w *writeInPlaceHandlerImpl) FinishWriteInPlace(evaluatedSuccessfully bool) error { func (w *writeInPlaceHandlerImpl) FinishWriteInPlace(evaluatedSuccessfully bool) error {
log.Debug("Going to write in place, evaluatedSuccessfully=%v, target=%v", evaluatedSuccessfully, w.inputFilename) log.Debugf("Going to write in place, evaluatedSuccessfully=%v, target=%v", evaluatedSuccessfully, w.inputFilename)
safelyCloseFile(w.tempFile) safelyCloseFile(w.tempFile)
if evaluatedSuccessfully { if evaluatedSuccessfully {
log.Debug("Moving temp file to target") log.Debug("Moving temp file to target")

View File

@ -109,6 +109,7 @@ hostpath
hotdog hotdog
howdy howdy
incase incase
Infof
inlinetables inlinetables
inplace inplace
ints ints

View File

@ -1,3 +1,9 @@
4.52.5:
- Fix: reset TOML decoder state between files (#2634) thanks @terminalchai
- Fix: preserve original filename when using --front-matter (#2613) thanks @cobyfrombrooklyn-bot
- Fix typo in filename (#2611) thanks @alexandear
- Bumped dependencies
4.52.4: 4.52.4:
- Dropping windows/arm - no longer supported in cross-compile - Dropping windows/arm - no longer supported in cross-compile

View File

@ -1,5 +1,5 @@
name: yq name: yq
version: 'v4.52.4' version: 'v4.52.5'
summary: A lightweight and portable command-line data file processor summary: A lightweight and portable command-line data file processor
description: | description: |
`yq` uses [jq](https://github.com/stedolan/jq) like syntax but works with yaml, json, xml, csv, properties and TOML files. `yq` uses [jq](https://github.com/stedolan/jq) like syntax but works with yaml, json, xml, csv, properties and TOML files.
@ -32,6 +32,6 @@ parts:
build-environment: build-environment:
- CGO_ENABLED: 0 - CGO_ENABLED: 0
source: https://github.com/mikefarah/yq.git source: https://github.com/mikefarah/yq.git
source-tag: v4.52.4 source-tag: v4.52.5
build-snaps: build-snaps:
- go/latest/stable - go/latest/stable

View File

@ -14,6 +14,7 @@ func TestMainFunction(t *testing.T) {
cmd := command.New() cmd := command.New()
if cmd == nil { if cmd == nil {
t.Fatal("command.New() returned nil") t.Fatal("command.New() returned nil")
return
} }
if cmd.Use != "yq" { if cmd.Use != "yq" {
@ -99,6 +100,7 @@ func TestMainFunctionExecution(t *testing.T) {
// the command structure is correct and can be configured // the command structure is correct and can be configured
if cmd == nil { if cmd == nil {
t.Fatal("Command should not be nil") t.Fatal("Command should not be nil")
return
} }
if cmd.Use != "yq" { if cmd.Use != "yq" {