Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix help and usage for tink template update #587

Merged
merged 3 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions cmd/tink-cli/cmd/template/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package template
import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/google/uuid"
"github.com/spf13/cobra"
Expand All @@ -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 --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())
if !isInputFromPipe() {
if filePath == "" {
return fmt.Errorf("%v requires the '--path' flag", c.UseLine())
}
}
return nil
},
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions tools.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//go:build tools
// +build tools

package tools

Expand Down