mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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:
+10
-3
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user