command.go
This file
Path
format/command.go
49 lines · 973 bytes · Go
Last changed by
chore: prepare v2 (#1116)Drew Smirnoffbefore adoption02d6f06
History of this fileTake it
1// Package format allows you to render formatted text from the command line.2//3// It supports the following types:4//5// 1. Markdown6// 2. Code7// 3. Emoji8// 4. Template9//10// For more information, see the format/README.md file.11package format1213import (14 "fmt"15 "strings"1617 "charm.land/gum/v2/internal/stdin"18 "charm.land/gum/v2/internal/tty"19)2021// Run runs the format command.22func (o Options) Run() error {23 var input, output string24 var err error25 if len(o.Template) > 0 {26 input = strings.Join(o.Template, "\n")27 } else {28 input, _ = stdin.Read(stdin.StripANSI(o.StripANSI))29 }3031 switch o.Type {32 case "code":33 output, err = code(input, o.Language)34 case "emoji":35 output, err = emoji(input)36 case "template":37 output, err = template(input)38 default:39 output, err = markdown(input, o.Theme)40 }41 if err != nil {42 return err43 }4445 if _, err := fmt.Fprint(tty.Writer(), output); err != nil {46 return fmt.Errorf("unable to write output: %w", err)47 }48 return nil49}