yqlib

package
v4.25.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Use the top level Evaluator or StreamEvaluator to evaluate expressions and return matches.

Index

Constants

View Source
const (
	YamlInputFormat = 1 << iota
	XMLInputFormat
	PropertiesInputFormat
	Base64InputFormat
)
View Source
const (
	YamlOutputFormat = 1 << iota
	JSONOutputFormat
	PropsOutputFormat
	CSVOutputFormat
	TSVOutputFormat
	XMLOutputFormat
	Base64OutputFormat
)

Variables

View Source
var Now = time.Now

for unit tests

View Source
var PrettyPrintExp = `(... | (select(tag != "!!str"), select(tag == "!!str") | select(test("(?i)^(y|yes|n|no|on|off)$") | not))  ) style=""`
View Source
var XMLPreferences = xmlPreferences{AttributePrefix: "+", ContentName: "+content", StrictMode: false}

Functions

func GetLogger

func GetLogger() *logging.Logger

GetLogger returns the yq logger instance.

func InitExpressionParser

func InitExpressionParser()

func KindString

func KindString(kind yaml.Kind) string

func NewFrontMatterHandler

func NewFrontMatterHandler(originalFilename string) frontMatterHandler

func NewWriteInPlaceHandler

func NewWriteInPlaceHandler(inputFile string) writeInPlaceHandler

func NodeToString

func NodeToString(node *CandidateNode) string

func NodesToString

func NodesToString(collection *list.List) string

use for debugging only

func SafelyCloseReader

func SafelyCloseReader(reader io.Reader)

Types

type CandidateNode

type CandidateNode struct {
	Node   *yaml.Node     // the actual node
	Parent *CandidateNode // parent node
	Key    *yaml.Node     // node key, if this is a value from a map (or index in an array)

	LeadingContent  string
	TrailingContent string

	Path      []interface{} /// the path we took to get to this node
	Document  uint          // the document index of this node
	Filename  string
	FileIndex int
	// when performing op against all nodes given, this will treat all the nodes as one
	// (e.g. top level cross document merge). This property does not propagate to child nodes.
	EvaluateTogether bool
	IsMapKey         bool
}

func (*CandidateNode) AsList

func (n *CandidateNode) AsList() *list.List

func (*CandidateNode) Copy

func (n *CandidateNode) Copy() (*CandidateNode, error)

func (*CandidateNode) CreateChildInArray

func (n *CandidateNode) CreateChildInArray(index int, node *yaml.Node) *CandidateNode

func (*CandidateNode) CreateChildInMap

func (n *CandidateNode) CreateChildInMap(key *yaml.Node, node *yaml.Node) *CandidateNode

func (*CandidateNode) CreateReplacement

func (n *CandidateNode) CreateReplacement(node *yaml.Node) *CandidateNode

func (*CandidateNode) GetKey

func (n *CandidateNode) GetKey() string

func (*CandidateNode) GetNicePath

func (n *CandidateNode) GetNicePath() string

func (*CandidateNode) GetNiceTag

func (n *CandidateNode) GetNiceTag() string

func (*CandidateNode) UpdateAttributesFrom

func (n *CandidateNode) UpdateAttributesFrom(other *CandidateNode, prefs assignPreferences)

func (*CandidateNode) UpdateFrom

func (n *CandidateNode) UpdateFrom(other *CandidateNode, prefs assignPreferences)

updates this candidate from the given candidate node

type Context

type Context struct {
	MatchingNodes  *list.List
	Variables      map[string]*list.List
	DontAutoCreate bool
	// contains filtered or unexported fields
}

func (*Context) ChildContext

func (n *Context) ChildContext(results *list.List) Context

func (*Context) Clone

func (n *Context) Clone() Context

func (*Context) DeepClone

func (n *Context) DeepClone() Context

func (*Context) GetDateTimeLayout

func (n *Context) GetDateTimeLayout() string

func (*Context) GetVariable

func (n *Context) GetVariable(name string) *list.List

func (*Context) ReadOnlyClone

func (n *Context) ReadOnlyClone() Context

func (*Context) SetDateTimeLayout

func (n *Context) SetDateTimeLayout(newDateTimeLayout string)

func (*Context) SetVariable

func (n *Context) SetVariable(name string, value *list.List)

func (*Context) SingleChildContext

func (n *Context) SingleChildContext(candidate *CandidateNode) Context

func (*Context) SingleReadonlyChildContext

func (n *Context) SingleReadonlyChildContext(candidate *CandidateNode) Context

func (*Context) ToString

func (n *Context) ToString() string

func (*Context) WritableClone

func (n *Context) WritableClone() Context

type DataTreeNavigator

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)
}

func NewDataTreeNavigator

func NewDataTreeNavigator() DataTreeNavigator

type Decoder

type Decoder interface {
	Init(reader io.Reader)
	Decode(node *yaml.Node) error
}

func NewBase64Decoder

func NewBase64Decoder() Decoder

func NewPropertiesDecoder

func NewPropertiesDecoder() Decoder

func NewXMLDecoder

func NewXMLDecoder(attributePrefix string, contentName string, strictMode bool) Decoder

func NewYamlDecoder

func NewYamlDecoder() Decoder

type Encoder

type Encoder interface {
	Encode(writer io.Writer, node *yaml.Node) error
	PrintDocumentSeparator(writer io.Writer) error
	PrintLeadingContent(writer io.Writer, content string) error
	CanHandleAliases() bool
}

func NewBase64Encoder

func NewBase64Encoder() Encoder

func NewCsvEncoder

func NewCsvEncoder(separator rune) Encoder

func NewJONEncoder

func NewJONEncoder(indent int, colorise bool) Encoder

func NewPropertiesEncoder

func NewPropertiesEncoder() Encoder

func NewXMLEncoder

func NewXMLEncoder(indent int, attributePrefix string, contentName string) Encoder

func NewYamlEncoder

func NewYamlEncoder(indent int, colorise bool, printDocSeparators bool, unwrapScalar bool) Encoder

type Evaluator

type Evaluator interface {
	EvaluateFiles(expression string, filenames []string, printer Printer, leadingContentPreProcessing bool, decoder Decoder) error

	// EvaluateNodes takes an expression and one or more yaml nodes, returning a list of matching candidate nodes
	EvaluateNodes(expression string, nodes ...*yaml.Node) (*list.List, error)

	// EvaluateCandidateNodes takes an expression and list of candidate nodes, returning a list of matching candidate nodes
	EvaluateCandidateNodes(expression string, inputCandidateNodes *list.List) (*list.List, error)
}

A yaml expression evaluator that runs the expression once against all files/nodes in memory.

func NewAllAtOnceEvaluator

func NewAllAtOnceEvaluator(stripComments bool) Evaluator

type ExpressionNode

type ExpressionNode struct {
	Operation *Operation
	LHS       *ExpressionNode
	RHS       *ExpressionNode
}

type ExpressionParserInterface

type ExpressionParserInterface interface {
	ParseExpression(expression string) (*ExpressionNode, error)
}
var ExpressionParser ExpressionParserInterface

type InputFormat

type InputFormat uint

func InputFormatFromString

func InputFormatFromString(format string) (InputFormat, error)

type Operation

type Operation struct {
	OperationType *operationType
	Value         interface{}
	StringValue   string
	CandidateNode *CandidateNode // used for Value Path elements
	Preferences   interface{}
	UpdateAssign  bool // used for assign ops, when true it means we evaluate the rhs given the lhs
}

type Printer

type Printer interface {
	PrintResults(matchingNodes *list.List) error
	PrintedAnything() bool
	//e.g. when given a front-matter doc, like jekyll
	SetAppendix(reader io.Reader)
}

func NewPrinter

func NewPrinter(encoder Encoder, printerWriter PrinterWriter) Printer

type PrinterOutputFormat

type PrinterOutputFormat uint32

func OutputFormatFromString

func OutputFormatFromString(format string) (PrinterOutputFormat, error)

type PrinterWriter

type PrinterWriter interface {
	GetWriter(node *CandidateNode) (*bufio.Writer, error)
}

func NewMultiPrinterWriter

func NewMultiPrinterWriter(expression *ExpressionNode, format PrinterOutputFormat) PrinterWriter

func NewSinglePrinterWriter

func NewSinglePrinterWriter(writer io.Writer) PrinterWriter

type StreamEvaluator

type StreamEvaluator interface {
	Evaluate(filename string, reader io.Reader, node *ExpressionNode, printer Printer, leadingContent string, decoder Decoder) (uint, error)
	EvaluateFiles(expression string, filenames []string, printer Printer, leadingContentPreProcessing bool, decoder Decoder) error
	EvaluateNew(expression string, printer Printer, leadingContent string) error
}

A yaml expression evaluator that runs the expression multiple times for each given yaml document. Uses less memory than loading all documents and running the expression once, but this cannot process cross document expressions.

func NewStreamEvaluator

func NewStreamEvaluator(stripComments bool) StreamEvaluator

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL