formatted

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: Apache-2.0 Imports: 10 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EncodeOptions

type EncodeOptions struct {
	// Indent specifies how many spaces to use per-indentation
	Indent int `yaml:"indent"`

	// GapExpressions specifies a list of yq-style paths for which the path's YAML
	// element's children elements should be separated by an empty line
	GapExpressions []string `yaml:"gap"`

	// SortExpressions specifies a list of yq-style paths for which the path's YAML
	// element's children elements should be sorted
	SortExpressions []string `yaml:"sort"`
}

EncodeOptions describes the set of configuration options used to adjust the behavior of yam's YAML encoder.

func ReadConfig

func ReadConfig() (*EncodeOptions, error)

ReadConfig tries to load a yam encoder config from a `.yam.yaml` file in the current working directory. It returns an error if it wasn't able to open or unmarshal the file.

func ReadConfigFrom

func ReadConfigFrom(r io.Reader) (*EncodeOptions, error)

ReadConfigFrom loads a yam encoder config from the given io.Reader. It returns an error if it wasn't able to unmarshal the data.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is an implementation of a YAML encoder that applies a configurable formatting to the YAML data as it's written out to the encoder's io.Writer.

func NewEncoder

func NewEncoder(w io.Writer) Encoder

NewEncoder returns a new encoder that can write formatted YAML to the given io.Writer.

func (Encoder) AutomaticConfig

func (enc Encoder) AutomaticConfig() Encoder

AutomaticConfig configures the encoder using a `.yam.yaml` config file in the current working directory, if one exists. This method is meant to work on a "best effort" basis, and all errors are silently ignored.

func (Encoder) Encode

func (enc Encoder) Encode(node *yaml.Node) error

Encode writes out the formatted YAML from the given yaml.Node to the encoder's io.Writer.

func (Encoder) SetGapExpressions

func (enc Encoder) SetGapExpressions(expressions ...string) (Encoder, error)

SetGapExpressions takes 0 or more YAML path expressions (e.g. "." or ".something.foo") and configures the encoder to insert empty lines ("gaps") in between the children elements of the YAML nodes referenced by the path expressions.

func (Encoder) SetIndent

func (enc Encoder) SetIndent(spaces int) Encoder

SetIndent configures the encoder to use the provided number of spaces for each indentation.

func (Encoder) SetSortExpressions

func (enc Encoder) SetSortExpressions(expressions ...string) (Encoder, error)

SetSortExpressions takes 0 or more YAML path expressions (e.g. "." or ".something.foo") and configures the encoder to sort the arrays.

func (Encoder) UseOptions

func (enc Encoder) UseOptions(options EncodeOptions) (Encoder, error)

UseOptions configures the encoder to use the configuration from the given EncodeOptions.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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