feat: make 'templates update [name]' optional (#2761)

- If the name is not specified the current working directory
  name is used or the name specified by "--directory". This
  reflects 'templates create" behavior.
This commit is contained in:
Jon Ayers
2022-07-01 11:49:29 -05:00
committed by GitHub
parent 0dbfd265fb
commit 554d9917c0
2 changed files with 65 additions and 3 deletions
+10 -3
View File
@@ -3,6 +3,7 @@ package cli
import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/briandowns/spinner"
@@ -24,8 +25,8 @@ func templateUpdate() *cobra.Command {
)
cmd := &cobra.Command{
Use: "update <template>",
Args: cobra.ExactArgs(1),
Use: "update [template]",
Args: cobra.MaximumNArgs(1),
Short: "Update the source-code of a template from the current directory or as specified by flag",
RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd)
@@ -36,7 +37,13 @@ func templateUpdate() *cobra.Command {
if err != nil {
return err
}
template, err := client.TemplateByName(cmd.Context(), organization.ID, args[0])
name := filepath.Base(directory)
if len(args) > 0 {
name = args[0]
}
template, err := client.TemplateByName(cmd.Context(), organization.ID, name)
if err != nil {
return err
}