From 614f0e80288fd68a69e841c690cdd5fa35277116 Mon Sep 17 00:00:00 2001 From: Maas Lalani Date: Wed, 9 Nov 2022 23:13:21 -0500 Subject: [PATCH] feat(style): allow passing input over stdin --- style/command.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/style/command.go b/style/command.go index a8045ac..5412ec7 100644 --- a/style/command.go +++ b/style/command.go @@ -6,16 +6,27 @@ package style import ( + "errors" "fmt" "strings" "github.com/alecthomas/kong" + "github.com/charmbracelet/gum/internal/stdin" ) // Run provides a shell script interface for the Lip Gloss styling. // https://github.com/charmbracelet/lipgloss func (o Options) Run() error { - text := strings.Join(o.Text, "\n") + var text string + if len(o.Text) > 0 { + text = strings.Join(o.Text, "\n") + } else { + text, _ = stdin.Read() + if text == "" { + return errors.New("no input provided, see `gum style --help`") + } + text = strings.TrimSuffix(text, "\n") + } fmt.Println(o.Style.ToLipgloss().Render(text)) return nil }