Documentation ¶
Overview ¶
Package transform defines some useful transformations on TOML documents.
Index ¶
- func FindTable(doc *tomledit.Document, name ...string) *tomledit.Entry
- func InsertMapping(tab *tomledit.Section, kv *parser.KeyValue, replace bool) bool
- func SortKeyValuesByName(items []parser.Item)
- func SortSectionsByName(ss []*tomledit.Section)
- func WithLogWriter(ctx context.Context, w io.Writer) context.Context
- type Applier
- type Func
- type Plan
- type Step
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindTable ¶ added in v0.0.3
FindTable returns the entry the first table with the given name in doc, or nil if no such table exists. An empty name denotes the global table.
func InsertMapping ¶ added in v0.0.14
InsertMapping inserts the specified key-value mapping into the given table. If replace is true, the new value replaces an existing one with that name, otherwise the original value is retained. The function reports true if kv was inserted or replaced an existing value, otherwise false.
func SortKeyValuesByName ¶ added in v0.0.8
SortKeyValuesByName performs a stable in-place sort of items, so that any key-value entries are ordered by their names, but other items such as comments are left in their original positions.
func SortSectionsByName ¶ added in v0.0.6
SortSectionsByName performs a stable in-place sort of the given slice of sections by their name.
Types ¶
type Applier ¶
An Applier applies one or more transformations to a document. The Func, Step, and Plan types implement this interface.
type Func ¶ added in v0.0.5
A Func implements the applier interface with a function.
func EnsureKey ¶ added in v0.0.4
EnsureKey ensures the given table contains a mapping for the given key, adding kv if it it is not already present. It reports an error if the table does not exist.
func MoveKey ¶
MoveKey moves the mapping at oldKey from its current location to be a child of rootKey with the new name newKey. It reports whether the key was moved.
func Remove ¶
Remove removes the section or mapping at the given keys, and reports whether the removals were successful. All the removals are attempted before returning.
func Rename ¶
Rename renames the section or mapping at oldKey to newKey, and reports whether the rename was successful. The mapping is not moved within the document, only its label is changed.
func SnakeToKebab ¶
func SnakeToKebab() Func
SnakeToKebab transforms all the key names in doc from snake_case to kebab-case. This transformation cannot fail.