yq

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 9 Imported by: 7

README

🌳 Query YAML Data

GoDoc License

This is the same popular yq tool (written in Go) that uses the same yqlib code but as a Bonzai composite command (instead of Cobra) making it more portable and usable in one's own Bonzai command tree monoliths and multicall binaries along with other commands. It includes simplified Evaluate and EvaluateToString high-level functions calling into the yqlib with reasonable defaults allowing other non-Bonzai applications to easily duplicate the same functionality.

Install

This command can be installed as a standalone program or composed into a Bonzai command tree.

Standalone

go install github.com/rwxrob/yq/cmd/yq@latest

Composed

package z

import (
	Z "github.com/rwxrob/bonzai/z"
	"github.com/rwxrob/yq"
)

var Cmd = &Z.Cmd{
	Name:     `cmds`,
	Commands: []*Z.Cmd{help.Cmd, yq.Cmd},
}

Tab Completion

To activate bash completion just use the complete -C option from your .bashrc or command line. There is no messy sourcing required. All the completion is done by the program itself.

complete -C yq yq

If you don't have bash or tab completion check use the shortcut commands instead.

Embedded Documentation

All documentation (like manual pages) has been embedded into the source code of the application. See the source or run the program with help to access it.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &Z.Cmd{

	Name:      `yq`,
	Summary:   `query YAML and JSON files`,
	Usage:     `(help|<expression>) [<file>...]`,
	Comp:      compfile.New(),
	Version:   `v0.3.2`,
	Copyright: `Copyright 2021 Robert S Muhlestein`,
	License:   `Apache-2.0`,
	Commands:  []*Z.Cmd{help.Cmd},

	Description: `
		The {{cmd .Name}} command allows YAML (and JSON, since all JSON is YAML)
		files to be queried using a simple syntax that is nearly identical
		to the popular stedolan/jq tool (written in C). In fact, {{cmd .Name}} uses
		the same *yqlib* that the {{cmd .Name}} tool does (just without the Cobra).

		The first argument is the <expression> and almost always begins with
		a dot (.). See the <https://github.com/stedolan/jq> project for
		exact syntax (until more documentation is updated here to contain
		the same).

		The remaining arguments are the names of one or more files. If no
		file argument is passed standard input is assumed (per UNIX filter
		philosophy). Note that the special dash (-) filename is not
		supported even though it was in the original {{cmd .Name}} tool.`,

	Call: func(x *Z.Cmd, args ...string) error {
		var files []string
		switch len(args) {
		case 1:
			files = append(files, "-")
		case 0:
			return x.UsageError()
		default:
			files = append(files, args...)
		}
		return Evaluate(args[0], args[1:]...)
	},
}

Functions

func Evaluate added in v0.3.0

func Evaluate(expr string, files ...string) error

Evaluate creates a yqlib Evaluator and applies it to one or more files with reasonable, predictable defaults for logging, decoding, and printing. Only YAML files are supported. Will read from standard input if no arguments are passed.

func EvaluateToString added in v0.3.0

func EvaluateToString(expr string, files ...string) (string, error)

EvaluateToString is the same as Evaluate but returns a string with the output instead.

func NewPrinter added in v0.3.0

func NewPrinter(
	w io.Writer,
	f yqlib.PrinterOutputFormat,
	unwrap bool,
	colors bool,
	indent int,
	sep bool,
) yqlib.Printer

NewPrinter is a convenience function for dealing with all the many things that must be configured properly to get a usable yqlib.Printer. This is useful for testing as well.

Types

This section is empty.

Directories

Path Synopsis
cmd
yq

Jump to

Keyboard shortcuts

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