yqlib

package
v4.31.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 35 Imported by: 47

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
	JsonInputFormat
	CSVObjectInputFormat
	TSVObjectInputFormat
	UriInputFormat
)
View Source
const (
	YamlOutputFormat = 1 << iota
	JSONOutputFormat
	PropsOutputFormat
	CSVOutputFormat
	TSVOutputFormat
	XMLOutputFormat
	Base64OutputFormat
	UriOutputFormat
	ShOutputFormat
)

Variables

View Source
var ConfiguredXMLPreferences = NewDefaultXmlPreferences()
View Source
var ConfiguredYamlPreferences = NewDefaultYamlPreferences()
View Source
var LoadYamlPreferences = YamlPreferences{
	LeadingContentPreProcessing: false,
	PrintDocSeparators:          true,
	UnwrapScalar:                true,
	EvaluateTogether:            false,
}
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=""`

Functions

func GetLogger added in v4.16.1

func GetLogger() *logging.Logger

GetLogger returns the yq logger instance.

func InitExpressionParser added in v4.19.1

func InitExpressionParser()

func KindString

func KindString(kind yaml.Kind) string

func NewFrontMatterHandler added in v4.11.0

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 added in v4.11.0

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 added in v4.14.1

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

func (*CandidateNode) Copy

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

func (*CandidateNode) CreateChildInArray added in v4.15.1

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

func (*CandidateNode) CreateChildInMap added in v4.15.1

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

func (*CandidateNode) CreateReplacement added in v4.15.1

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

func (*CandidateNode) CreateReplacementWithDocWrappers added in v4.25.3

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

func (*CandidateNode) GetKey

func (n *CandidateNode) GetKey() string

func (*CandidateNode) GetNicePath added in v4.16.2

func (n *CandidateNode) GetNicePath() string

func (*CandidateNode) GetNiceTag added in v4.16.2

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 added in v4.5.0

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

func (*Context) ChildContext added in v4.5.0

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

func (*Context) Clone added in v4.5.1

func (n *Context) Clone() Context

func (*Context) DeepClone added in v4.13.0

func (n *Context) DeepClone() Context

func (*Context) GetDateTimeLayout added in v4.20.1

func (n *Context) GetDateTimeLayout() string

func (*Context) GetVariable added in v4.5.0

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

func (*Context) ReadOnlyClone added in v4.9.2

func (n *Context) ReadOnlyClone() Context

func (*Context) SetDateTimeLayout added in v4.20.1

func (n *Context) SetDateTimeLayout(newDateTimeLayout string)

func (*Context) SetVariable added in v4.5.0

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

func (*Context) SingleChildContext added in v4.5.0

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

func (*Context) SingleReadonlyChildContext added in v4.9.2

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

func (*Context) ToString added in v4.12.2

func (n *Context) ToString() string

func (*Context) WritableClone added in v4.9.7

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 added in v4.17.1

type Decoder interface {
	Init(reader io.Reader) error
	Decode() (*CandidateNode, error)
}

func NewBase64Decoder added in v4.21.1

func NewBase64Decoder() Decoder

func NewCSVObjectDecoder added in v4.27.1

func NewCSVObjectDecoder(separator rune) Decoder

func NewJSONDecoder added in v4.27.1

func NewJSONDecoder() Decoder

func NewPropertiesDecoder added in v4.20.1

func NewPropertiesDecoder() Decoder

func NewUriDecoder added in v4.31.1

func NewUriDecoder() Decoder

func NewXMLDecoder added in v4.20.1

func NewXMLDecoder(prefs XmlPreferences) Decoder

func NewYamlDecoder added in v4.17.1

func NewYamlDecoder(prefs YamlPreferences) 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 added in v4.21.1

func NewBase64Encoder() Encoder

func NewCsvEncoder added in v4.16.1

func NewCsvEncoder(separator rune) Encoder

func NewJSONEncoder added in v4.27.1

func NewJSONEncoder(indent int, colorise bool, unwrapScalar bool) Encoder

func NewPropertiesEncoder added in v4.12.0

func NewPropertiesEncoder(unwrapScalar bool) Encoder

func NewShEncoder added in v4.31.1

func NewShEncoder() Encoder

func NewUriEncoder added in v4.31.1

func NewUriEncoder() Encoder

func NewXMLEncoder added in v4.20.1

func NewXMLEncoder(indent int, prefs XmlPreferences) Encoder

func NewYamlEncoder

func NewYamlEncoder(indent int, colorise bool, prefs YamlPreferences) Encoder

type Evaluator

type Evaluator interface {
	EvaluateFiles(expression string, filenames []string, printer Printer, 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() Evaluator

type ExpressionNode added in v4.3.2

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

type ExpressionParserInterface added in v4.19.1

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

type InputFormat added in v4.17.1

type InputFormat uint

func InputFormatFromString added in v4.17.1

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 added in v4.12.0

type PrinterOutputFormat uint32

func OutputFormatFromString added in v4.12.0

func OutputFormatFromString(format string) (PrinterOutputFormat, error)

type PrinterWriter added in v4.14.1

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

func NewMultiPrinterWriter added in v4.14.1

func NewMultiPrinterWriter(expression *ExpressionNode, format PrinterOutputFormat) PrinterWriter

func NewSinglePrinterWriter added in v4.14.1

func NewSinglePrinterWriter(writer io.Writer) PrinterWriter

type StreamEvaluator

type StreamEvaluator interface {
	Evaluate(filename string, reader io.Reader, node *ExpressionNode, printer Printer, decoder Decoder) (uint, error)
	EvaluateFiles(expression string, filenames []string, printer Printer, decoder Decoder) error
	EvaluateNew(expression string, printer Printer) 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() StreamEvaluator

type StringEvaluator added in v4.27.1

type StringEvaluator interface {
	Evaluate(expression string, input string, encoder Encoder, decoder Decoder) (string, error)
}

func NewStringEvaluator added in v4.27.1

func NewStringEvaluator() StringEvaluator

type XmlPreferences added in v4.17.1

type XmlPreferences struct {
	AttributePrefix string
	ContentName     string
	StrictMode      bool
	KeepNamespace   bool
	UseRawToken     bool
	ProcInstPrefix  string
	DirectiveName   string
	SkipProcInst    bool
	SkipDirectives  bool
}

func NewDefaultXmlPreferences added in v4.29.1

func NewDefaultXmlPreferences() XmlPreferences

type YamlPreferences added in v4.29.1

type YamlPreferences struct {
	LeadingContentPreProcessing bool
	PrintDocSeparators          bool
	UnwrapScalar                bool
	EvaluateTogether            bool
}

func NewDefaultYamlPreferences added in v4.29.1

func NewDefaultYamlPreferences() YamlPreferences

Source Files

Jump to

Keyboard shortcuts

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