summaryrefslogtreecommitdiffstats
path: root/dependencies/pkg/mod/github.com/goccy/go-yaml@v1.11.3/cmd
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:41:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 11:41:39 +0000
commitfcfb5e62f95d625836328131cc5ca851182bcae4 (patch)
tree5309ef2284a82d61ece838d1dd1c97c09df152b8 /dependencies/pkg/mod/github.com/goccy/go-yaml@v1.11.3/cmd
parentAdding upstream version 1.1.1. (diff)
downloadicingadb-upstream/1.2.0.tar.xz
icingadb-upstream/1.2.0.zip
Adding upstream version 1.2.0.upstream/1.2.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dependencies/pkg/mod/github.com/goccy/go-yaml@v1.11.3/cmd')
-rw-r--r--dependencies/pkg/mod/github.com/goccy/go-yaml@v1.11.3/cmd/ycat/ycat.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/dependencies/pkg/mod/github.com/goccy/go-yaml@v1.11.3/cmd/ycat/ycat.go b/dependencies/pkg/mod/github.com/goccy/go-yaml@v1.11.3/cmd/ycat/ycat.go
new file mode 100644
index 0000000..c70cb3b
--- /dev/null
+++ b/dependencies/pkg/mod/github.com/goccy/go-yaml@v1.11.3/cmd/ycat/ycat.go
@@ -0,0 +1,83 @@
+package main
+
+import (
+ "errors"
+ "fmt"
+ "io/ioutil"
+ "os"
+
+ "github.com/fatih/color"
+ "github.com/goccy/go-yaml"
+ "github.com/goccy/go-yaml/lexer"
+ "github.com/goccy/go-yaml/printer"
+ "github.com/mattn/go-colorable"
+)
+
+const escape = "\x1b"
+
+func format(attr color.Attribute) string {
+ return fmt.Sprintf("%s[%dm", escape, attr)
+}
+
+func _main(args []string) error {
+ if len(args) < 2 {
+ return errors.New("ycat: usage: ycat file.yml")
+ }
+ filename := args[1]
+ bytes, err := ioutil.ReadFile(filename)
+ if err != nil {
+ return err
+ }
+ tokens := lexer.Tokenize(string(bytes))
+ var p printer.Printer
+ p.LineNumber = true
+ p.LineNumberFormat = func(num int) string {
+ fn := color.New(color.Bold, color.FgHiWhite).SprintFunc()
+ return fn(fmt.Sprintf("%2d | ", num))
+ }
+ p.Bool = func() *printer.Property {
+ return &printer.Property{
+ Prefix: format(color.FgHiMagenta),
+ Suffix: format(color.Reset),
+ }
+ }
+ p.Number = func() *printer.Property {
+ return &printer.Property{
+ Prefix: format(color.FgHiMagenta),
+ Suffix: format(color.Reset),
+ }
+ }
+ p.MapKey = func() *printer.Property {
+ return &printer.Property{
+ Prefix: format(color.FgHiCyan),
+ Suffix: format(color.Reset),
+ }
+ }
+ p.Anchor = func() *printer.Property {
+ return &printer.Property{
+ Prefix: format(color.FgHiYellow),
+ Suffix: format(color.Reset),
+ }
+ }
+ p.Alias = func() *printer.Property {
+ return &printer.Property{
+ Prefix: format(color.FgHiYellow),
+ Suffix: format(color.Reset),
+ }
+ }
+ p.String = func() *printer.Property {
+ return &printer.Property{
+ Prefix: format(color.FgHiGreen),
+ Suffix: format(color.Reset),
+ }
+ }
+ writer := colorable.NewColorableStdout()
+ writer.Write([]byte(p.PrintTokens(tokens) + "\n"))
+ return nil
+}
+
+func main() {
+ if err := _main(os.Args); err != nil {
+ fmt.Printf("%v\n", yaml.FormatError(err, true, true))
+ }
+}