From 00b7368dbbc6e69547535d57f2873ca30258ecce Mon Sep 17 00:00:00 2001 From: Jason DeTiberus Date: Wed, 9 Feb 2022 11:12:48 -0500 Subject: [PATCH 1/3] Add missing build tag for tools.go --- tools.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tools.go b/tools.go index 177df0590..4abdeca73 100644 --- a/tools.go +++ b/tools.go @@ -1,4 +1,5 @@ //go:build tools +// +build tools package tools From 157b3f98643055e0b27d649f93c7f31bfe2b4843 Mon Sep 17 00:00:00 2001 From: Jason DeTiberus Date: Wed, 9 Feb 2022 11:13:44 -0500 Subject: [PATCH 2/3] Fix help output for `tink template update` command --- cmd/tink-cli/cmd/template/update.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/tink-cli/cmd/template/update.go b/cmd/tink-cli/cmd/template/update.go index fe7dadc7b..fa94ee6d7 100644 --- a/cmd/tink-cli/cmd/template/update.go +++ b/cmd/tink-cli/cmd/template/update.go @@ -21,11 +21,11 @@ func NewUpdateCommand() *cobra.Command { Short: "update a workflow template", Long: `The update command allows you change the definition of an existing workflow template: # Update an existing template: -$ tink template update 614168df-45a5-11eb-b13d-0242ac120003 --file /tmp/example.tmpl +$ tink template update 614168df-45a5-11eb-b13d-0242ac120003 --path /tmp/example.tmpl `, PreRunE: func(c *cobra.Command, args []string) error { if filePath == "" { - return fmt.Errorf("%v requires the '--file' flag", c.UseLine()) + return fmt.Errorf("%v requires the '--path' flag", c.UseLine()) } return nil }, From 239df244f4cad0a38e92b3d6d6817bdaef5dc3b0 Mon Sep 17 00:00:00 2001 From: Jason DeTiberus Date: Wed, 9 Feb 2022 11:25:07 -0500 Subject: [PATCH 3/3] Support stdin for `tink template update` --- cmd/tink-cli/cmd/template/update.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/cmd/tink-cli/cmd/template/update.go b/cmd/tink-cli/cmd/template/update.go index fa94ee6d7..58a0461d6 100644 --- a/cmd/tink-cli/cmd/template/update.go +++ b/cmd/tink-cli/cmd/template/update.go @@ -3,9 +3,11 @@ package template import ( "context" "fmt" + "io" "io/ioutil" "log" "os" + "path/filepath" "github.com/google/uuid" "github.com/spf13/cobra" @@ -20,12 +22,16 @@ func NewUpdateCommand() *cobra.Command { Use: "update [id] [flags]", Short: "update a workflow template", Long: `The update command allows you change the definition of an existing workflow template: +# Pipe the file to create a template: +$ cat /tmp/example.tmpl | tink template update 614168df-45a5-11eb-b13d-0242ac120003 # Update an existing template: $ tink template update 614168df-45a5-11eb-b13d-0242ac120003 --path /tmp/example.tmpl `, PreRunE: func(c *cobra.Command, args []string) error { - if filePath == "" { - return fmt.Errorf("%v requires the '--path' flag", c.UseLine()) + if !isInputFromPipe() { + if filePath == "" { + return fmt.Errorf("%v requires the '--path' flag", c.UseLine()) + } } return nil }, @@ -79,15 +85,24 @@ func updateTemplate(id string) { } func readTemplateData() (string, error) { - f, err := os.Open(filePath) - if err != nil { - return "", err + var reader io.Reader + if isInputFromPipe() { + reader = os.Stdin + } else { + f, err := os.Open(filepath.Clean(filePath)) + if err != nil { + return "", err + } + + defer f.Close() + + reader = f } - defer f.Close() - data, err := ioutil.ReadAll(f) + data, err := ioutil.ReadAll(reader) if err != nil { return "", err } + return string(data), nil }