Cleaning up log message formats

This commit is contained in:
Mike Farah 2024-02-16 09:41:33 +11:00
parent 9142c93d1b
commit 3c3f1180d9
32 changed files with 75 additions and 75 deletions

View File

@ -39,18 +39,19 @@ yq -P -oy sample.json
}, },
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
cmd.SetOut(cmd.OutOrStdout()) cmd.SetOut(cmd.OutOrStdout())
level := logging.WARNING
stringFormat := `[%{level}] %{color}%{time:15:04:05}%{color:reset} %{message}`
var format = logging.MustStringFormatter( if verbose {
`[%{level:5.5s}] %{color}%{time:15:04:05} %{color:bold} %{shortfile:-30s} %{shortfunc:-25s}%{color:reset} %{message}`, level = logging.DEBUG
) stringFormat = `[%{level:5.5s}] %{color}%{time:15:04:05}%{color:bold} %{shortfile:-33s} %{shortfunc:-25s}%{color:reset} %{message}`
}
var format = logging.MustStringFormatter(stringFormat)
var backend = logging.AddModuleLevel( var backend = logging.AddModuleLevel(
logging.NewBackendFormatter(logging.NewLogBackend(os.Stderr, "", 0), format)) logging.NewBackendFormatter(logging.NewLogBackend(os.Stderr, "", 0), format))
if verbose { backend.SetLevel(level, "")
backend.SetLevel(logging.DEBUG, "")
} else {
backend.SetLevel(logging.WARNING, "")
}
logging.SetBackend(backend) logging.SetBackend(backend)
yqlib.InitExpressionParser() yqlib.InitExpressionParser()

View File

@ -27,7 +27,7 @@ func (d *dataTreeNavigator) DeeplyAssign(context Context, path []interface{}, rh
assignmentOp := &Operation{OperationType: assignOpType, Preferences: assignPreferences{}} assignmentOp := &Operation{OperationType: assignOpType, Preferences: assignPreferences{}}
if rhsCandidateNode.Kind == MappingNode { if rhsCandidateNode.Kind == MappingNode {
log.Debug("[DataTreeNavigator] DeeplyAssign: deeply merging object") log.Debug("DeeplyAssign: deeply merging object")
// if the rhs is a map, we need to deeply merge it in. // if the rhs is a map, we need to deeply merge it in.
// otherwise we'll clobber any existing fields // otherwise we'll clobber any existing fields
assignmentOp = &Operation{OperationType: multiplyAssignOpType, Preferences: multiplyPreferences{ assignmentOp = &Operation{OperationType: multiplyAssignOpType, Preferences: multiplyPreferences{

View File

@ -56,7 +56,7 @@ func (dec *tomlDecoder) getFullPath(tomlNode *toml.Node) []interface{} {
func (dec *tomlDecoder) processKeyValueIntoMap(rootMap *CandidateNode, tomlNode *toml.Node) error { func (dec *tomlDecoder) processKeyValueIntoMap(rootMap *CandidateNode, tomlNode *toml.Node) error {
value := tomlNode.Value() value := tomlNode.Value()
path := dec.getFullPath(value.Next()) path := dec.getFullPath(value.Next())
log.Debug("[DecoderTOML] processKeyValueIntoMap: %v", path) log.Debug("processKeyValueIntoMap: %v", path)
valueNode, err := dec.decodeNode(value) valueNode, err := dec.decodeNode(value)
if err != nil { if err != nil {
@ -70,14 +70,14 @@ func (dec *tomlDecoder) processKeyValueIntoMap(rootMap *CandidateNode, tomlNode
} }
func (dec *tomlDecoder) decodeKeyValuesIntoMap(rootMap *CandidateNode, tomlNode *toml.Node) (bool, error) { func (dec *tomlDecoder) decodeKeyValuesIntoMap(rootMap *CandidateNode, tomlNode *toml.Node) (bool, error) {
log.Debug("[DecoderTOML] decodeKeyValuesIntoMap -- processing first (current) entry") log.Debug("decodeKeyValuesIntoMap -- processing first (current) entry")
if err := dec.processKeyValueIntoMap(rootMap, tomlNode); err != nil { if err := dec.processKeyValueIntoMap(rootMap, tomlNode); err != nil {
return false, err return false, err
} }
for dec.parser.NextExpression() { for dec.parser.NextExpression() {
nextItem := dec.parser.Expression() nextItem := dec.parser.Expression()
log.Debug("[DecoderTOML] decodeKeyValuesIntoMap -- next exp, its a %v", nextItem.Kind) log.Debug("decodeKeyValuesIntoMap -- next exp, its a %v", nextItem.Kind)
if nextItem.Kind == toml.KeyValue { if nextItem.Kind == toml.KeyValue {
if err := dec.processKeyValueIntoMap(rootMap, nextItem); err != nil { if err := dec.processKeyValueIntoMap(rootMap, nextItem); err != nil {
@ -85,18 +85,17 @@ func (dec *tomlDecoder) decodeKeyValuesIntoMap(rootMap *CandidateNode, tomlNode
} }
} else { } else {
// run out of key values // run out of key values
log.Debug("! DECODE_KV_INTO_MAP - ok we are done in decodeKeyValuesIntoMap, gota a %v", nextItem.Kind) log.Debug("done in decodeKeyValuesIntoMap, gota a %v", nextItem.Kind)
log.Debug("! DECODE_KV_INTO_MAP - processAgainstCurrentExp = true!")
return true, nil return true, nil
} }
} }
log.Debug("! DECODE_KV_INTO_MAP - no more things to read in") log.Debug("no more things to read in")
return false, nil return false, nil
} }
func (dec *tomlDecoder) createInlineTableMap(tomlNode *toml.Node) (*CandidateNode, error) { func (dec *tomlDecoder) createInlineTableMap(tomlNode *toml.Node) (*CandidateNode, error) {
content := make([]*CandidateNode, 0) content := make([]*CandidateNode, 0)
log.Debug("!! createInlineTableMap") log.Debug("createInlineTableMap")
iterator := tomlNode.Children() iterator := tomlNode.Children()
for iterator.Next() { for iterator.Next() {
@ -249,7 +248,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("[DecoderTOML] processTopLevelNode: Going to process %v state is current %v", currentNode.Kind, NodeToString(dec.rootMap)) log.Debug("processTopLevelNode: Going to process %v state is current %v", currentNode.Kind, NodeToString(dec.rootMap))
if currentNode.Kind == toml.Table { if currentNode.Kind == toml.Table {
runAgainstCurrentExp, err = dec.processTable(currentNode) runAgainstCurrentExp, err = dec.processTable(currentNode)
} else if currentNode.Kind == toml.ArrayTable { } else if currentNode.Kind == toml.ArrayTable {
@ -258,14 +257,14 @@ 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("[DecoderTOML] processTopLevelNode: DONE Processing state is now %v", NodeToString(dec.rootMap)) log.Debug("processTopLevelNode: DONE Processing state is now %v", NodeToString(dec.rootMap))
return runAgainstCurrentExp, err return runAgainstCurrentExp, err
} }
func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) { func (dec *tomlDecoder) processTable(currentNode *toml.Node) (bool, error) {
log.Debug("[DecoderTOML] Enter processTable") log.Debug("Enter processTable")
fullPath := dec.getFullPath(currentNode.Child()) fullPath := dec.getFullPath(currentNode.Child())
log.Debug("[DecoderTOML] fullpath: %v", fullPath) log.Debug("fullpath: %v", fullPath)
tableNodeValue := &CandidateNode{ tableNodeValue := &CandidateNode{
Kind: MappingNode, Kind: MappingNode,
@ -302,7 +301,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("[DecoderTOML] arrayAppend to path: %v,%v", path, NodeToString(rhsNode)) log.Debug("arrayAppend to path: %v,%v", path, NodeToString(rhsNode))
rhsCandidateNode := &CandidateNode{ rhsCandidateNode := &CandidateNode{
Kind: SequenceNode, Kind: SequenceNode,
Tag: "!!seq", Tag: "!!seq",
@ -324,9 +323,9 @@ func (dec *tomlDecoder) arrayAppend(context Context, path []interface{}, rhsNode
} }
func (dec *tomlDecoder) processArrayTable(currentNode *toml.Node) (bool, error) { func (dec *tomlDecoder) processArrayTable(currentNode *toml.Node) (bool, error) {
log.Debug("[DecoderTOML] Entering processArrayTable") log.Debug("Entering processArrayTable")
fullPath := dec.getFullPath(currentNode.Child()) fullPath := dec.getFullPath(currentNode.Child())
log.Debug("[DecoderTOML] Fullpath: %v", fullPath) log.Debug("Fullpath: %v", fullPath)
// need to use the array append exp to add another entry to // need to use the array append exp to add another entry to
// this array: fullpath += [ thing ] // this array: fullpath += [ thing ]

View File

@ -30,7 +30,7 @@ func (ye *yamlEncoder) CanHandleAliases() bool {
func (ye *yamlEncoder) PrintDocumentSeparator(writer io.Writer) error { func (ye *yamlEncoder) PrintDocumentSeparator(writer io.Writer) error {
if ye.prefs.PrintDocSeparators { if ye.prefs.PrintDocSeparators {
log.Debug("-- writing doc sep") log.Debug("writing doc sep")
if err := writeString(writer, "---\n"); err != nil { if err := writeString(writer, "---\n"); err != nil {
return err return err
} }

View File

@ -111,11 +111,11 @@ func handleToken(tokens []*token, index int, postProcessedTokens []*token) (toke
//need to put a traverse array then a collect currentToken //need to put a traverse array then a collect currentToken
// do this by adding traverse then converting currentToken to collect // do this by adding traverse then converting currentToken to collect
log.Debug(" adding self") log.Debug("adding self")
op := &Operation{OperationType: selfReferenceOpType, StringValue: "SELF"} op := &Operation{OperationType: selfReferenceOpType, StringValue: "SELF"}
postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op}) postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op})
log.Debug(" adding traverse array") log.Debug("adding traverse array")
op = &Operation{OperationType: traverseArrayOpType, StringValue: "TRAVERSE_ARRAY"} op = &Operation{OperationType: traverseArrayOpType, StringValue: "TRAVERSE_ARRAY"}
postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op}) postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op})
@ -135,13 +135,13 @@ func handleToken(tokens []*token, index int, postProcessedTokens []*token) (toke
if index != len(tokens)-1 && currentToken.AssignOperation != nil && if index != len(tokens)-1 && currentToken.AssignOperation != nil &&
tokenIsOpType(tokens[index+1], assignOpType) { tokenIsOpType(tokens[index+1], assignOpType) {
log.Debug(" its an update assign") log.Debug("its an update assign")
currentToken.Operation = currentToken.AssignOperation currentToken.Operation = currentToken.AssignOperation
currentToken.Operation.UpdateAssign = tokens[index+1].Operation.UpdateAssign currentToken.Operation.UpdateAssign = tokens[index+1].Operation.UpdateAssign
skipNextToken = true skipNextToken = true
} }
log.Debug(" adding token to the fixed list") log.Debug("adding token to the fixed list")
postProcessedTokens = append(postProcessedTokens, currentToken) postProcessedTokens = append(postProcessedTokens, currentToken)
if tokenIsOpType(currentToken, createMapOpType) { if tokenIsOpType(currentToken, createMapOpType) {
@ -158,7 +158,7 @@ func handleToken(tokens []*token, index int, postProcessedTokens []*token) (toke
if index != len(tokens)-1 && if index != len(tokens)-1 &&
((currentToken.TokenType == openCollect && tokens[index+1].TokenType == closeCollect) || ((currentToken.TokenType == openCollect && tokens[index+1].TokenType == closeCollect) ||
(currentToken.TokenType == openCollectObject && tokens[index+1].TokenType == closeCollectObject)) { (currentToken.TokenType == openCollectObject && tokens[index+1].TokenType == closeCollectObject)) {
log.Debug(" adding empty") log.Debug("adding empty")
op := &Operation{OperationType: emptyOpType, StringValue: "EMPTY"} op := &Operation{OperationType: emptyOpType, StringValue: "EMPTY"}
postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op}) postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op})
} }
@ -167,14 +167,14 @@ func handleToken(tokens []*token, index int, postProcessedTokens []*token) (toke
(tokenIsOpType(tokens[index+1], traversePathOpType) || (tokenIsOpType(tokens[index+1], traversePathOpType) ||
(tokens[index+1].TokenType == traverseArrayCollect)) { (tokens[index+1].TokenType == traverseArrayCollect)) {
log.Debug(" adding pipe because the next thing is traverse") log.Debug("adding pipe because the next thing is traverse")
op := &Operation{OperationType: shortPipeOpType, Value: "PIPE", StringValue: "."} op := &Operation{OperationType: shortPipeOpType, Value: "PIPE", StringValue: "."}
postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op}) postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op})
} }
if index != len(tokens)-1 && currentToken.CheckForPostTraverse && if index != len(tokens)-1 && currentToken.CheckForPostTraverse &&
tokens[index+1].TokenType == openCollect { tokens[index+1].TokenType == openCollect {
log.Debug(" adding traverseArray because next is opencollect") log.Debug("adding traverseArray because next is opencollect")
op := &Operation{OperationType: traverseArrayOpType} op := &Operation{OperationType: traverseArrayOpType}
postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op}) postProcessedTokens = append(postProcessedTokens, &token{TokenType: operationToken, Operation: op})
} }

View File

@ -1,7 +1,7 @@
package yqlib package yqlib
func alternativeOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func alternativeOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- alternative") log.Debugf("alternative")
prefs := crossFunctionPreferences{ prefs := crossFunctionPreferences{
CalcWhenEmpty: true, CalcWhenEmpty: true,
Calculation: alternativeFunc, Calculation: alternativeFunc,

View File

@ -116,7 +116,7 @@ func getAnchorOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode)
} }
func explodeOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func explodeOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- ExplodeOperation") log.Debugf("ExplodeOperation")
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)

View File

@ -137,7 +137,7 @@ func andOperator(d *dataTreeNavigator, context Context, expressionNode *Expressi
} }
func notOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) { func notOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {
log.Debugf("-- notOperation") log.Debugf("notOperation")
var results = list.New() var results = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {

View File

@ -22,7 +22,7 @@ func collectTogether(d *dataTreeNavigator, context Context, expressionNode *Expr
} }
func collectOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func collectOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- collectOperation") log.Debugf("collectOperation")
if context.MatchingNodes.Len() == 0 { if context.MatchingNodes.Len() == 0 {
log.Debugf("nothing to collect") log.Debugf("nothing to collect")

View File

@ -16,13 +16,13 @@ import (
*/ */
func collectObjectOperator(d *dataTreeNavigator, originalContext Context, _ *ExpressionNode) (Context, error) { func collectObjectOperator(d *dataTreeNavigator, originalContext Context, _ *ExpressionNode) (Context, error) {
log.Debugf("-- collectObjectOperation") log.Debugf("collectObjectOperation")
context := originalContext.WritableClone() context := originalContext.WritableClone()
if context.MatchingNodes.Len() == 0 { if context.MatchingNodes.Len() == 0 {
candidate := &CandidateNode{Kind: MappingNode, Tag: "!!map", Value: "{}"} candidate := &CandidateNode{Kind: MappingNode, Tag: "!!map", Value: "{}"}
log.Debugf("-- collectObjectOperation - starting with empty map") log.Debugf("collectObjectOperation - starting with empty map")
return context.SingleChildContext(candidate), nil return context.SingleChildContext(candidate), nil
} }
first := context.MatchingNodes.Front().Value.(*CandidateNode) first := context.MatchingNodes.Front().Value.(*CandidateNode)
@ -41,7 +41,7 @@ func collectObjectOperator(d *dataTreeNavigator, originalContext Context, _ *Exp
rotated[i].PushBack(candidateNode.Content[i]) rotated[i].PushBack(candidateNode.Content[i])
} }
} }
log.Debugf("-- collectObjectOperation, length of rotated is %v", len(rotated)) log.Debugf("collectObjectOperation, length of rotated is %v", len(rotated))
newObject := list.New() newObject := list.New()
for i := 0; i < len(first.Content); i++ { for i := 0; i < len(first.Content); i++ {
@ -58,7 +58,7 @@ func collectObjectOperator(d *dataTreeNavigator, originalContext Context, _ *Exp
additionCopy.SetParent(nil) additionCopy.SetParent(nil)
additionCopy.Key = nil additionCopy.Key = nil
log.Debugf("-- collectObjectOperation, adding result %v", NodeToString(additionCopy)) log.Debugf("collectObjectOperation, adding result %v", NodeToString(additionCopy))
newObject.PushBack(additionCopy) newObject.PushBack(additionCopy)
} }
@ -74,7 +74,7 @@ func collect(d *dataTreeNavigator, context Context, remainingMatches *list.List)
} }
candidate := remainingMatches.Remove(remainingMatches.Front()).(*CandidateNode) candidate := remainingMatches.Remove(remainingMatches.Front()).(*CandidateNode)
log.Debugf("-- collectObjectOperation - collect %v", NodeToString(candidate)) log.Debugf("collectObjectOperation - collect %v", NodeToString(candidate))
splatted, err := splat(context.SingleChildContext(candidate), splatted, err := splat(context.SingleChildContext(candidate),
traversePreferences{DontFollowAlias: true, IncludeMapKeys: false}) traversePreferences{DontFollowAlias: true, IncludeMapKeys: false})
@ -84,7 +84,7 @@ func collect(d *dataTreeNavigator, context Context, remainingMatches *list.List)
} }
if context.MatchingNodes.Len() == 0 { if context.MatchingNodes.Len() == 0 {
log.Debugf("-- collectObjectOperation - collect context is empty, next") log.Debugf("collectObjectOperation - collect context is empty, next")
return collect(d, splatted, remainingMatches) return collect(d, splatted, remainingMatches)
} }
@ -94,9 +94,9 @@ func collect(d *dataTreeNavigator, context Context, remainingMatches *list.List)
aggCandidate := el.Value.(*CandidateNode) aggCandidate := el.Value.(*CandidateNode)
for splatEl := splatted.MatchingNodes.Front(); splatEl != nil; splatEl = splatEl.Next() { for splatEl := splatted.MatchingNodes.Front(); splatEl != nil; splatEl = splatEl.Next() {
splatCandidate := splatEl.Value.(*CandidateNode) splatCandidate := splatEl.Value.(*CandidateNode)
log.Debugf("-- collectObjectOperation; splatCandidate: %v", NodeToString(splatCandidate)) log.Debugf("collectObjectOperation; splatCandidate: %v", NodeToString(splatCandidate))
newCandidate := aggCandidate.Copy() newCandidate := aggCandidate.Copy()
log.Debugf("-- collectObjectOperation; aggCandidate: %v", NodeToString(aggCandidate)) log.Debugf("collectObjectOperation; aggCandidate: %v", NodeToString(aggCandidate))
newCandidate, err = multiply(multiplyPreferences{AppendArrays: false})(d, context, newCandidate, splatCandidate) newCandidate, err = multiply(multiplyPreferences{AppendArrays: false})(d, context, newCandidate, splatCandidate)

View File

@ -11,14 +11,14 @@ type compareTypePref struct {
} }
func compareOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func compareOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- compareOperator") log.Debugf("compareOperator")
prefs := expressionNode.Operation.Preferences.(compareTypePref) prefs := expressionNode.Operation.Preferences.(compareTypePref)
return crossFunction(d, context, expressionNode, compare(prefs), true) return crossFunction(d, context, expressionNode, compare(prefs), true)
} }
func compare(prefs compareTypePref) func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { func compare(prefs compareTypePref) func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
return func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { return func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
log.Debugf("-- compare cross function") log.Debugf("compare cross function")
if lhs == nil && rhs == nil { if lhs == nil && rhs == nil {
owner := &CandidateNode{} owner := &CandidateNode{}
return createBooleanCandidate(owner, prefs.OrEqual), nil return createBooleanCandidate(owner, prefs.OrEqual), nil

View File

@ -5,7 +5,7 @@ import (
) )
func createMapOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func createMapOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- createMapOperation") log.Debugf("createMapOperation")
//each matchingNodes entry should turn into a sequence of keys to create. //each matchingNodes entry should turn into a sequence of keys to create.
//then collect object should do a cross function of the same index sequence for all matches. //then collect object should do a cross function of the same index sequence for all matches.

View File

@ -165,7 +165,7 @@ func withEntriesOperator(d *dataTreeNavigator, context Context, expressionNode *
collected.HeadComment = candidate.HeadComment collected.HeadComment = candidate.HeadComment
collected.FootComment = candidate.FootComment collected.FootComment = candidate.FootComment
log.Debugf("**** collected %v", collected.LeadingContent) log.Debugf("collected %v", collected.LeadingContent)
fromEntries, err := fromEntriesOperator(d, context.SingleChildContext(collected), expressionNode) fromEntries, err := fromEntriesOperator(d, context.SingleChildContext(collected), expressionNode)
if err != nil { if err != nil {

View File

@ -1,16 +1,16 @@
package yqlib package yqlib
func equalsOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func equalsOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- equalsOperation") log.Debugf("equalsOperation")
return crossFunction(d, context, expressionNode, isEquals(false), true) return crossFunction(d, context, expressionNode, isEquals(false), true)
} }
func isEquals(flip bool) func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { func isEquals(flip bool) func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
return func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) { return func(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs *CandidateNode) (*CandidateNode, error) {
value := false value := false
log.Debugf("-- isEquals cross function") log.Debugf("isEquals cross function")
if lhs == nil && rhs == nil { if lhs == nil && rhs == nil {
log.Debugf("-- both are nil") log.Debugf("both are nil")
owner := &CandidateNode{} owner := &CandidateNode{}
return createBooleanCandidate(owner, !flip), nil return createBooleanCandidate(owner, !flip), nil
} else if lhs == nil { } else if lhs == nil {
@ -43,6 +43,6 @@ func isEquals(flip bool) func(d *dataTreeNavigator, context Context, lhs *Candid
} }
func notEqualsOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func notEqualsOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- notEqualsOperator") log.Debugf("notEqualsOperator")
return crossFunction(d, context.ReadOnlyClone(), expressionNode, isEquals(true), true) return crossFunction(d, context.ReadOnlyClone(), expressionNode, isEquals(true), true)
} }

View File

@ -6,7 +6,7 @@ import (
func errorOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func errorOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- errorOperation") log.Debugf("errorOperation")
rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS) rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)
if err != nil { if err != nil {

View File

@ -5,7 +5,7 @@ import (
) )
func filterOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func filterOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- filterOperation") log.Debugf("filterOperation")
var results = list.New() var results = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {

View File

@ -34,7 +34,7 @@ func flatten(node *CandidateNode, depth int) {
func flattenOp(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func flattenOp(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- flatten Operator") log.Debugf("flatten Operator")
depth := expressionNode.Operation.Preferences.(flattenPreferences).depth depth := expressionNode.Operation.Preferences.(flattenPreferences).depth
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {

View File

@ -37,7 +37,7 @@ func processIntoGroups(d *dataTreeNavigator, context Context, rhsExp *Expression
func groupBy(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func groupBy(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- groupBy Operator") log.Debugf("groupBy Operator")
var results = list.New() var results = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {

View File

@ -7,7 +7,7 @@ import (
func hasOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func hasOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- hasOperation") log.Debugf("hasOperation")
var results = list.New() var results = list.New()
rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS) rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)

View File

@ -6,7 +6,7 @@ import (
) )
func isKeyOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) { func isKeyOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {
log.Debugf("-- isKeyOperator") log.Debugf("isKeyOperator")
var results = list.New() var results = list.New()
@ -20,7 +20,7 @@ func isKeyOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Co
} }
func getKeyOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) { func getKeyOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {
log.Debugf("-- getKeyOperator") log.Debugf("getKeyOperator")
var results = list.New() var results = list.New()
@ -37,7 +37,7 @@ func getKeyOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (C
} }
func keysOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) { func keysOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {
log.Debugf("-- keysOperator") log.Debugf("keysOperator")
var results = list.New() var results = list.New()

View File

@ -6,7 +6,7 @@ import (
) )
func lengthOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) { func lengthOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {
log.Debugf("-- lengthOperation") log.Debugf("lengthOperation")
var results = list.New() var results = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {

View File

@ -29,7 +29,7 @@ func multiplyAssignOperator(d *dataTreeNavigator, context Context, expressionNod
} }
func multiplyOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func multiplyOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- MultiplyOperator") log.Debugf("MultiplyOperator")
return crossFunction(d, context, expressionNode, multiply(expressionNode.Operation.Preferences.(multiplyPreferences)), false) return crossFunction(d, context, expressionNode, multiply(expressionNode.Operation.Preferences.(multiplyPreferences)), false)
} }
@ -54,7 +54,7 @@ func multiply(preferences multiplyPreferences) func(d *dataTreeNavigator, contex
// need to do this before unWrapping the potential document node // need to do this before unWrapping the potential document node
leadingContent, headComment, footComment := getComments(lhs, rhs) leadingContent, headComment, footComment := getComments(lhs, rhs)
log.Debugf("Multiplying LHS: %v", NodeToString(lhs)) log.Debugf("Multiplying LHS: %v", NodeToString(lhs))
log.Debugf("- RHS: %v", NodeToString(rhs)) log.Debugf("- RHS: %v", NodeToString(rhs))
if rhs.Tag == "!!null" { if rhs.Tag == "!!null" {
return lhs.Copy(), nil return lhs.Copy(), nil
@ -157,7 +157,7 @@ func mergeObjects(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs
for el := results.Front(); el != nil; el = el.Next() { for el := results.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode) candidate := el.Value.(*CandidateNode)
log.Debugf("*** going to applied assignment to LHS: %v with RHS: %v", NodeToString(lhs), NodeToString(candidate)) log.Debugf("going to applied assignment to LHS: %v with RHS: %v", NodeToString(lhs), NodeToString(candidate))
if candidate.Tag == "!!merge" { if candidate.Tag == "!!merge" {
continue continue
@ -168,7 +168,7 @@ func mergeObjects(d *dataTreeNavigator, context Context, lhs *CandidateNode, rhs
return nil, err return nil, err
} }
log.Debugf("*** applied assignment to LHS: %v", NodeToString(lhs)) log.Debugf("applied assignment to LHS: %v", NodeToString(lhs))
} }
return lhs, nil return lhs, nil
} }

View File

@ -3,7 +3,7 @@ package yqlib
import "container/list" import "container/list"
func getParentOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) { func getParentOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {
log.Debugf("-- getParentOperator") log.Debugf("getParentOperator")
var results = list.New() var results = list.New()

View File

@ -25,7 +25,7 @@ func recursiveDecent(results *list.List, context Context, preferences recursiveD
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.Debugf("Recursive Decent, added %v", NodeToString(candidate)) log.Debugf("added %v", NodeToString(candidate))
results.PushBack(candidate) results.PushBack(candidate)
if candidate.Kind != AliasNode && len(candidate.Content) > 0 && if candidate.Kind != AliasNode && len(candidate.Content) > 0 &&

View File

@ -6,7 +6,7 @@ import (
) )
func reduceOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func reduceOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- reduceOp") log.Debugf("reduceOp")
//.a as $var reduce (0; . + $var) //.a as $var reduce (0; . + $var)
//lhs is the assignment operator //lhs is the assignment operator
//rhs is the reduce block //rhs is the reduce block

View File

@ -6,7 +6,7 @@ import (
func selectOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func selectOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- selectOperation") log.Debugf("selectOperation")
var results = list.New() var results = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {

View File

@ -1,7 +1,7 @@
package yqlib package yqlib
func splitDocumentOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) { func splitDocumentOperator(_ *dataTreeNavigator, context Context, _ *ExpressionNode) (Context, error) {
log.Debugf("-- splitDocumentOperator") log.Debugf("splitDocumentOperator")
var index uint var index uint
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {

View File

@ -338,7 +338,7 @@ func testOperator(d *dataTreeNavigator, context Context, expressionNode *Express
} }
func joinStringOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func joinStringOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- joinStringOperator") log.Debugf("joinStringOperator")
joinStr := "" joinStr := ""
rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS) rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)
@ -377,7 +377,7 @@ func join(content []*CandidateNode, joinStr string) (Kind, string, string) {
} }
func splitStringOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func splitStringOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- splitStringOperator") log.Debugf("splitStringOperator")
splitStr := "" splitStr := ""
rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS) rhs, err := d.GetMatchingNodes(context.ReadOnlyClone(), expressionNode.RHS)

View File

@ -20,7 +20,7 @@ func splat(context Context, prefs traversePreferences) (Context, error) {
} }
func traversePathOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func traversePathOperator(_ *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- traversePathOperator") log.Debugf("traversePathOperator")
var matches = list.New() var matches = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {

View File

@ -16,7 +16,7 @@ func unique(d *dataTreeNavigator, context Context, _ *ExpressionNode) (Context,
func uniqueBy(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func uniqueBy(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- uniqueBy Operator") log.Debugf("uniqueBy Operator")
var results = list.New() var results = list.New()
for el := context.MatchingNodes.Front(); el != nil; el = el.Next() { for el := context.MatchingNodes.Front(); el != nil; el = el.Next() {

View File

@ -3,7 +3,7 @@ package yqlib
import "fmt" import "fmt"
func withOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) { func withOperator(d *dataTreeNavigator, context Context, expressionNode *ExpressionNode) (Context, error) {
log.Debugf("-- withOperator") log.Debugf("withOperator")
// with(path, exp) // with(path, exp)
if expressionNode.RHS.Operation.OperationType != blockOpType { if expressionNode.RHS.Operation.OperationType != blockOpType {

View File

@ -139,7 +139,7 @@ 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.Debug("print sep logic: p.firstTimePrinting: %v, previousDocIndex: %v", p.firstTimePrinting, p.previousDocIndex)
log.Debug("%v", NodeToString(mappedDoc)) log.Debug("%v", NodeToString(mappedDoc))
writer, errorWriting := p.printerWriter.GetWriter(mappedDoc) writer, errorWriting := p.printerWriter.GetWriter(mappedDoc)
if errorWriting != nil { if errorWriting != nil {