Skip to content
Myr

command.go

This file

Path

format/command.go

46 lines · 850 bytes · Go

Last changed by

feat: --no-strip-ansi (#784)Carlos Alexandro Beckerbefore adoption4cedf9f

History of this file

Take 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	"github.com/charmbracelet/gum/internal/stdin"18)1920// Run runs the format command.21func (o Options) Run() error {22	var input, output string23	var err error24	if len(o.Template) > 0 {25		input = strings.Join(o.Template, "\n")26	} else {27		input, _ = stdin.Read(stdin.StripANSI(o.StripANSI))28	}2930	switch o.Type {31	case "code":32		output, err = code(input, o.Language)33	case "emoji":34		output, err = emoji(input)35	case "template":36		output, err = template(input)37	default:38		output, err = markdown(input, o.Theme)39	}40	if err != nil {41		return err42	}4344	fmt.Print(output)45	return nil46}