mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(cli): validate name length on template create (#3823)
* feat(cli): add template create validation test This adds a test to validate that `template create` prints an error message if called with a template name exceeding the 32-char limit. * fixup * fixup test * feat(cli): add name validation to templatecreate This adds a validation step to ensure the template name is less than 32 characters. * fixup!: use utf8.RuneCountInString * fixup!: remove pty from test
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/briandowns/spinner"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -49,6 +50,10 @@ func templateCreate() *cobra.Command {
|
||||
templateName = args[0]
|
||||
}
|
||||
|
||||
if utf8.RuneCountInString(templateName) > 31 {
|
||||
return xerrors.Errorf("Template name must be less than 32 characters")
|
||||
}
|
||||
|
||||
_, err = client.TemplateByName(cmd.Context(), organization.ID, templateName)
|
||||
if err == nil {
|
||||
return xerrors.Errorf("A template already exists named %q!", templateName)
|
||||
|
||||
Reference in New Issue
Block a user