Documentation
¶
Index ¶
- Constants
- Variables
- func ColorizeYAML(code string, writer io.Writer) error
- func DumpYAMLNode(writer io.Writer, node *yaml.Node, indent int)
- func DumpYAMLNodes(writer io.Writer, node *yaml.Node)
- func NewJSONColorFormatter(indent int) *prettyjson.Formatter
- func NewUtterConfig(indent string) *utter.ConfigState
- func OpenFileForWrite(path string) (*os.File, error)
- type Transcriber
- func (self *Transcriber) Clone() *Transcriber
- func (self *Transcriber) SetBase64(base64 bool) *Transcriber
- func (self *Transcriber) SetFile(file string) *Transcriber
- func (self *Transcriber) SetForTerminal(forTerminal bool) *Transcriber
- func (self *Transcriber) SetFormat(format string) *Transcriber
- func (self *Transcriber) SetInPlace(inPlace bool) *Transcriber
- func (self *Transcriber) SetIndent(indent string) *Transcriber
- func (self *Transcriber) SetIndentSpaces(spaces int) *Transcriber
- func (self *Transcriber) SetReflector(reflector *ard.Reflector) *Transcriber
- func (self *Transcriber) SetStrict(strict bool) *Transcriber
- func (self *Transcriber) SetWriter(writer io.Writer) *Transcriber
- func (self *Transcriber) Stringify(value any) (string, error)
- func (self *Transcriber) StringifyCBOR(value any) (string, error)
- func (self *Transcriber) StringifyGo(value any) (string, error)
- func (self *Transcriber) StringifyJSON(value any) (string, error)
- func (self *Transcriber) StringifyMessagePack(value any) (string, error)
- func (self *Transcriber) StringifyXJSON(value any) (string, error)
- func (self *Transcriber) StringifyXML(value any) (string, error)
- func (self *Transcriber) StringifyYAML(value any) (string, error)
- func (self *Transcriber) Write(value any) error
- func (self *Transcriber) WriteCBOR(value any) error
- func (self *Transcriber) WriteGo(value any) error
- func (self *Transcriber) WriteJSON(value any) error
- func (self *Transcriber) WriteMessagePack(value any) error
- func (self *Transcriber) WriteString(value any) error
- func (self *Transcriber) WriteXJSON(value any) error
- func (self *Transcriber) WriteXML(value any) error
- func (self *Transcriber) WriteXMLDocument(xmlDocument *etree.Document) error
- func (self *Transcriber) WriteYAML(value any) error
Constants ¶
const DIRECTORY_WRITE_PERMISSIONS = 0700
const FILE_WRITE_PERMISSIONS = 0600
Variables ¶
var YAMLColorPrinter = yamlprinter.Printer{ String: func() *yamlprinter.Property { return &yamlprinter.Property{ Prefix: terminal.BlueCode, Suffix: terminal.ResetCode, } }, Number: func() *yamlprinter.Property { return &yamlprinter.Property{ Prefix: terminal.MagentaCode, Suffix: terminal.ResetCode, } }, Bool: func() *yamlprinter.Property { return &yamlprinter.Property{ Prefix: terminal.CyanCode, Suffix: terminal.ResetCode, } }, MapKey: func() *yamlprinter.Property { return &yamlprinter.Property{ Prefix: terminal.GreenCode, Suffix: terminal.ResetCode, } }, Anchor: func() *yamlprinter.Property { return &yamlprinter.Property{ Prefix: terminal.RedCode, Suffix: terminal.ResetCode, } }, Alias: func() *yamlprinter.Property { return &yamlprinter.Property{ Prefix: terminal.YellowCode, Suffix: terminal.ResetCode, } }, }
var YAMLNodeKinds = map[yaml.Kind]string{
yaml.DocumentNode: "Document",
yaml.SequenceNode: "Sequence",
yaml.MappingNode: "Mapping",
yaml.ScalarNode: "Scalar",
yaml.AliasNode: "Alias",
}
Functions ¶
func DumpYAMLNode ¶
func DumpYAMLNodes ¶
func NewJSONColorFormatter ¶
func NewJSONColorFormatter(indent int) *prettyjson.Formatter
func NewUtterConfig ¶
func NewUtterConfig(indent string) *utter.ConfigState
Types ¶
type Transcriber ¶ added in v0.2.0
type Transcriber struct { File string // if not empty will supersede Writer Writer io.Writer // if nil then os.Stdout will be used Format string // "yaml", "json", "xjson", "xml", "cbor", "messagepack", or "go" ForTerminal bool Indent string // used by YAML, JSON, XML, and Go Strict bool // used by YAML Base64 bool // used by CBOR and MessagePack InPlace bool // used by XJSON and XML Reflector *ard.Reflector // used by XJSON and XML }
func NewTranscriber ¶ added in v0.2.0
func NewTranscriber() *Transcriber
func (*Transcriber) Clone ¶ added in v0.3.0
func (self *Transcriber) Clone() *Transcriber
func (*Transcriber) SetBase64 ¶ added in v0.3.4
func (self *Transcriber) SetBase64(base64 bool) *Transcriber
func (*Transcriber) SetFile ¶ added in v0.3.4
func (self *Transcriber) SetFile(file string) *Transcriber
func (*Transcriber) SetForTerminal ¶ added in v0.3.4
func (self *Transcriber) SetForTerminal(forTerminal bool) *Transcriber
func (*Transcriber) SetFormat ¶ added in v0.3.4
func (self *Transcriber) SetFormat(format string) *Transcriber
func (*Transcriber) SetInPlace ¶ added in v0.3.4
func (self *Transcriber) SetInPlace(inPlace bool) *Transcriber
func (*Transcriber) SetIndent ¶ added in v0.3.4
func (self *Transcriber) SetIndent(indent string) *Transcriber
func (*Transcriber) SetIndentSpaces ¶ added in v0.3.4
func (self *Transcriber) SetIndentSpaces(spaces int) *Transcriber
func (*Transcriber) SetReflector ¶ added in v0.3.4
func (self *Transcriber) SetReflector(reflector *ard.Reflector) *Transcriber
func (*Transcriber) SetStrict ¶ added in v0.3.4
func (self *Transcriber) SetStrict(strict bool) *Transcriber
func (*Transcriber) SetWriter ¶ added in v0.3.4
func (self *Transcriber) SetWriter(writer io.Writer) *Transcriber
func (*Transcriber) Stringify ¶ added in v0.2.0
func (self *Transcriber) Stringify(value any) (string, error)
Converts the value to a string according to [Transcriber.Format]. If the format is any empty string will default to YAML.
The binary formats (CBOR and MessagePack) will be converted to base64, ensuring that the returned value is always a valid string.
func (*Transcriber) StringifyCBOR ¶ added in v0.2.0
func (self *Transcriber) StringifyCBOR(value any) (string, error)
Will always use base64.
func (*Transcriber) StringifyGo ¶ added in v0.2.0
func (self *Transcriber) StringifyGo(value any) (string, error)
func (*Transcriber) StringifyJSON ¶ added in v0.2.0
func (self *Transcriber) StringifyJSON(value any) (string, error)
func (*Transcriber) StringifyMessagePack ¶ added in v0.2.0
func (self *Transcriber) StringifyMessagePack(value any) (string, error)
Will always use base64.
func (*Transcriber) StringifyXJSON ¶ added in v0.2.0
func (self *Transcriber) StringifyXJSON(value any) (string, error)
func (*Transcriber) StringifyXML ¶ added in v0.2.0
func (self *Transcriber) StringifyXML(value any) (string, error)
func (*Transcriber) StringifyYAML ¶ added in v0.2.0
func (self *Transcriber) StringifyYAML(value any) (string, error)
Note special handling when value is []any. In this case, instead of writing a YAML seq, it will treat the value as a list of documents separated by "---".
func (*Transcriber) Write ¶ added in v0.2.0
func (self *Transcriber) Write(value any) error
Writes the value to a writer according to [Transcriber.Format]. If the format is any empty string will default to YAML.
If [Transcriber.File] is not empty will create the file and write to it. Sub-directories in the path will be created if they don't exist. Otherwise will write to [Transcriber.Writer], and if that is nil will write to stdout.
When [Transcriber.ForTerminal] is true will optimize for terminals, such as ensuring a newline at the end and colorization if supported by the format and the terminal. In this mode [Transcriber.Indent] is ignored and terminal.Indent will be used instead.
If value is a string then will ignore the format and use Transcriber.WriteString. If value is a *etree.Document will ignore the format and use Transcriber.WriteXMLDocument.
Note special handling for YAML when value is []any. In this case, instead of writing a YAML seq, it will treat the value as a list of documents separated by "---".
func (*Transcriber) WriteCBOR ¶ added in v0.2.0
func (self *Transcriber) WriteCBOR(value any) error
When [Transcriber.Base64] is true will first convert to base64 and will also add a trailing newline if [Self.ForTerminal] is true.
func (*Transcriber) WriteGo ¶ added in v0.2.0
func (self *Transcriber) WriteGo(value any) error
func (*Transcriber) WriteJSON ¶ added in v0.2.0
func (self *Transcriber) WriteJSON(value any) error
func (*Transcriber) WriteMessagePack ¶ added in v0.2.0
func (self *Transcriber) WriteMessagePack(value any) error
When [Transcriber.Base64] is true will first convert to base64 and will also add a trailing newline if [Self.ForTerminal] is true.
func (*Transcriber) WriteString ¶ added in v0.3.0
func (self *Transcriber) WriteString(value any) error
Converts the value to string (using util.ToString) and writes it, adding a newline if the string doesn't already have it.
func (*Transcriber) WriteXJSON ¶ added in v0.2.0
func (self *Transcriber) WriteXJSON(value any) error
If inPlace is false then the function is non-destructive: the written data structure is a ard.ValidCopy of the value argument. Otherwise, the value may be changed during preparing it for writing.
func (*Transcriber) WriteXML ¶ added in v0.2.0
func (self *Transcriber) WriteXML(value any) error
If inPlace is false then the function is non-destructive: the written data structure is a ard.ValidCopy of the value argument. Otherwise, the value may be changed during preparing it for writing.
func (*Transcriber) WriteXMLDocument ¶ added in v0.2.0
func (self *Transcriber) WriteXMLDocument(xmlDocument *etree.Document) error
Will change the indentation of the document.
func (*Transcriber) WriteYAML ¶ added in v0.2.0
func (self *Transcriber) WriteYAML(value any) error
Note special handling when value is []any. In this case, instead of writing a YAML seq, it will treat the value as a list of documents separated by "---".