From ac988d96552cae8180cc56bcc11816e7200b0eff Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 28 May 2021 16:48:36 +1000 Subject: [PATCH] wip --- pkg/yqlib/all_at_once_evaluator.go | 4 ++-- pkg/yqlib/data_tree_navigator.go | 10 +++++----- pkg/yqlib/encoder.go | 6 +++--- pkg/yqlib/operators_test.go | 4 ++-- pkg/yqlib/printer.go | 10 +++++----- pkg/yqlib/stream_evaluator.go | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/pkg/yqlib/all_at_once_evaluator.go b/pkg/yqlib/all_at_once_evaluator.go index cfb936b7..4a57027b 100644 --- a/pkg/yqlib/all_at_once_evaluator.go +++ b/pkg/yqlib/all_at_once_evaluator.go @@ -18,12 +18,12 @@ type Evaluator interface { } type allAtOnceEvaluator struct { - treeNavigator DataTreeNavigator + treeNavigator dataTreeNavigator treeCreator ExpressionParser } func NewAllAtOnceEvaluator() Evaluator { - return &allAtOnceEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewExpressionParser()} + return &allAtOnceEvaluator{treeNavigator: newDataTreeNavigator(), treeCreator: NewExpressionParser()} } func (e *allAtOnceEvaluator) EvaluateNodes(expression string, nodes ...*yaml.Node) (*list.List, error) { diff --git a/pkg/yqlib/data_tree_navigator.go b/pkg/yqlib/data_tree_navigator.go index 13659eaa..e51795b3 100644 --- a/pkg/yqlib/data_tree_navigator.go +++ b/pkg/yqlib/data_tree_navigator.go @@ -6,21 +6,21 @@ import ( logging "gopkg.in/op/go-logging.v1" ) -type DataTreeNavigator interface { +type dataTreeNavigator interface { // given the context and a expressionNode, // this will process the against the given expressionNode and return // a new context of matching candidates GetMatchingNodes(context Context, expressionNode *ExpressionNode) (Context, error) } -type dataTreeNavigator struct { +type dataTreeNavigatorImpl struct { } -func NewDataTreeNavigator() DataTreeNavigator { - return &dataTreeNavigator{} +func newDataTreeNavigator() dataTreeNavigator { + return &dataTreeNavigatorImpl{} } -func (d *dataTreeNavigator) GetMatchingNodes(context Context, expressionNode *ExpressionNode) (Context, error) { +func (d *dataTreeNavigatorImpl) GetMatchingNodes(context Context, expressionNode *ExpressionNode) (Context, error) { if expressionNode == nil { log.Debugf("getMatchingNodes - nothing to do") return context, nil diff --git a/pkg/yqlib/encoder.go b/pkg/yqlib/encoder.go index a77b57cb..0d6ced7e 100644 --- a/pkg/yqlib/encoder.go +++ b/pkg/yqlib/encoder.go @@ -9,7 +9,7 @@ import ( yaml "gopkg.in/yaml.v3" ) -type Encoder interface { +type encoder interface { Encode(node *yaml.Node) error } @@ -20,7 +20,7 @@ type yamlEncoder struct { firstDoc bool } -func NewYamlEncoder(destination io.Writer, indent int, colorise bool) Encoder { +func newYamlEncoder(destination io.Writer, indent int, colorise bool) encoder { if indent < 0 { indent = 0 } @@ -74,7 +74,7 @@ func mapKeysToStrings(node *yaml.Node) { } } -func NewJsonEncoder(destination io.Writer, indent int) Encoder { +func newJsonEncoder(destination io.Writer, indent int) encoder { var encoder = json.NewEncoder(destination) encoder.SetEscapeHTML(false) // do not escape html chars e.g. &, <, > diff --git a/pkg/yqlib/operators_test.go b/pkg/yqlib/operators_test.go index 6c1e3f04..340229f0 100644 --- a/pkg/yqlib/operators_test.go +++ b/pkg/yqlib/operators_test.go @@ -65,7 +65,7 @@ func testScenario(t *testing.T, s *expressionScenario) { os.Setenv("myenv", s.environmentVariable) } - context, err := NewDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node) + context, err := newDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node) if err != nil { t.Error(fmt.Errorf("%v: %v", err, s.expression)) @@ -251,7 +251,7 @@ func documentOutput(t *testing.T, w *bufio.Writer, s expressionScenario, formatt } - context, err := NewDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node) + context, err := newDataTreeNavigator().GetMatchingNodes(Context{MatchingNodes: inputs}, node) if err != nil { t.Error(err, s.expression) } diff --git a/pkg/yqlib/printer.go b/pkg/yqlib/printer.go index b4d9b9f0..51e10b30 100644 --- a/pkg/yqlib/printer.go +++ b/pkg/yqlib/printer.go @@ -24,7 +24,7 @@ type resultsPrinter struct { previousDocIndex uint previousFileIndex int printedMatches bool - treeNavigator DataTreeNavigator + treeNavigator dataTreeNavigator } func NewPrinter(writer io.Writer, outputToJSON bool, unwrapScalar bool, colorsEnabled bool, indent int, printDocSeparators bool) Printer { @@ -36,7 +36,7 @@ func NewPrinter(writer io.Writer, outputToJSON bool, unwrapScalar bool, colorsEn indent: indent, printDocSeparators: !outputToJSON && printDocSeparators, firstTimePrinting: true, - treeNavigator: NewDataTreeNavigator(), + treeNavigator: newDataTreeNavigator(), } } @@ -48,14 +48,14 @@ func (p *resultsPrinter) printNode(node *yaml.Node, writer io.Writer) error { p.printedMatches = p.printedMatches || (node.Tag != "!!null" && (node.Tag != "!!bool" || node.Value != "false")) - var encoder Encoder + var encoder encoder if node.Kind == yaml.ScalarNode && p.unwrapScalar && !p.outputToJSON { return p.writeString(writer, node.Value+"\n") } if p.outputToJSON { - encoder = NewJsonEncoder(writer, p.indent) + encoder = newJsonEncoder(writer, p.indent) } else { - encoder = NewYamlEncoder(writer, p.indent, p.colorsEnabled) + encoder = newYamlEncoder(writer, p.indent, p.colorsEnabled) } return encoder.Encode(node) } diff --git a/pkg/yqlib/stream_evaluator.go b/pkg/yqlib/stream_evaluator.go index 093c2777..e87c8cfb 100644 --- a/pkg/yqlib/stream_evaluator.go +++ b/pkg/yqlib/stream_evaluator.go @@ -18,13 +18,13 @@ type StreamEvaluator interface { } type streamEvaluator struct { - treeNavigator DataTreeNavigator + treeNavigator dataTreeNavigator treeCreator ExpressionParser fileIndex int } func NewStreamEvaluator() StreamEvaluator { - return &streamEvaluator{treeNavigator: NewDataTreeNavigator(), treeCreator: NewExpressionParser()} + return &streamEvaluator{treeNavigator: newDataTreeNavigator(), treeCreator: NewExpressionParser()} } func (s *streamEvaluator) EvaluateNew(expression string, printer Printer) error {