mirror of
https://github.com/mikefarah/yq.git
synced 2026-07-04 11:25:37 +00:00
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
This commit is contained in:
parent
b1c3059db8
commit
fcbf99ff43
25
cmd/root.go
25
cmd/root.go
@ -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
|
||||||
|
|||||||
16
cmd/utils.go
16
cmd/utils.go
@ -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:]
|
||||||
}
|
}
|
||||||
|
|||||||
1
go.mod
1
go.mod
@ -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 (
|
||||||
|
|||||||
2
go.sum
2
go.sum
@ -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=
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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)
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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)))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -106,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:
|
||||||
@ -118,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -271,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
|
||||||
@ -298,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
|
||||||
@ -326,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,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)
|
||||||
@ -402,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",
|
||||||
@ -427,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)
|
||||||
|
|||||||
@ -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}, " ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|
||||||
|
|||||||
@ -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") {
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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())
|
||||||
|
|||||||
@ -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())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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,
|
||||||
|
|||||||
@ -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
77
pkg/yqlib/logger.go
Normal 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...))
|
||||||
|
}
|
||||||
@ -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{
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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.
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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",
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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++ {
|
||||||
|
|||||||
@ -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) {
|
||||||
|
|||||||
@ -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))
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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")
|
||||||
|
|||||||
@ -109,6 +109,7 @@ hostpath
|
|||||||
hotdog
|
hotdog
|
||||||
howdy
|
howdy
|
||||||
incase
|
incase
|
||||||
|
Infof
|
||||||
inlinetables
|
inlinetables
|
||||||
inplace
|
inplace
|
||||||
ints
|
ints
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user