From c14dd1f3c6c796f290c7fd71ca50a3488955410a Mon Sep 17 00:00:00 2001 From: Samuel Marks <807580+SamuelMarks@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:29:14 -0500 Subject: [PATCH] [run.go] Add stdin support (`-c -` or `-f -`) --- run.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/run.go b/run.go index a6a8472b02..d3491751e0 100644 --- a/run.go +++ b/run.go @@ -1,6 +1,7 @@ package main import ( + "bufio" "context" "errors" "fmt" @@ -10,10 +11,8 @@ import ( "path/filepath" "strings" - "github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5/memfs" "github.com/go-git/go-billy/v5/osfs" - "github.com/mattn/go-isatty" "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/spf13/viper" @@ -404,6 +403,14 @@ type commandOrFile struct { // Set satisfies the [pflag.Value] interface. func (c commandOrFile) Set(value string) error { + if value == "-" { + scanner := bufio.NewScanner(os.Stdin) + scanner.Scan() + if err := scanner.Err(); err != nil { + return err + } + value = scanner.Text() + } c.args.CommandOrFiles = append(c.args.CommandOrFiles, CommandOrFile{ Command: c.command, Value: value,