Documentation ¶
Index ¶
- type EncodeOptions
- type Encoder
- func (enc Encoder) AutomaticConfig() Encoder
- func (enc Encoder) Encode(node *yaml.Node) error
- func (enc Encoder) SetGapExpressions(expressions ...string) (Encoder, error)
- func (enc Encoder) SetIndent(spaces int) Encoder
- func (enc Encoder) SetSortExpressions(expressions ...string) (Encoder, error)
- func (enc Encoder) UseOptions(options EncodeOptions) (Encoder, error)
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 ¶
NewEncoder returns a new encoder that can write formatted YAML to the given io.Writer.
func (Encoder) AutomaticConfig ¶
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 ¶
Encode writes out the formatted YAML from the given yaml.Node to the encoder's io.Writer.
func (Encoder) SetGapExpressions ¶
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 ¶
SetIndent configures the encoder to use the provided number of spaces for each indentation.
func (Encoder) SetSortExpressions ¶
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.