Documentation
¶
Overview ¶
Package cliformat provides a shared --format flag and output writer for Go CLI tools. Supported formats: name, yaml, json.
Usage:
cliformat.AddFlag(cmd, "name") // register --format on a cobra command
format := cliformat.GetFormat(cmd) // read the resolved value
cliformat.WriteList(w, format, items, func(d *MyType) string { return d.Name })
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ValidFormats = []string{"name", "yaml", "json"}
ValidFormats is the set of formats supported by WriteList.
Functions ¶
func AddFlag ¶
AddFlag registers a --format flag on cmd with the given default value. The flag description lists all ValidFormats.
func GetFormat ¶
GetFormat returns the resolved --format flag value from cmd (lower-cased). Returns an empty string if the flag was not registered.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.