-
Notifications
You must be signed in to change notification settings - Fork 894
feat(cli): add --create
flag to coder templates push
#8068
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
Changes from 25 commits
26fc837
d125251
f235f7c
f9b2ab2
d926d21
9199745
613e318
a85a0aa
c9220af
1e672a6
76fe001
eea488e
229af80
72291f5
910bfbb
9635d82
c99baaf
f4e6eab
d7272b9
379f670
3485352
8b31372
c3d87e9
66f9eb0
4eadcf7
c2b5c68
8794254
143e84d
2fc0729
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"github.com/coder/coder/cli/clibase" | ||
"github.com/coder/coder/cli/cliui" | ||
"github.com/coder/coder/coderd/database" | ||
"github.com/coder/coder/coderd/util/ptr" | ||
"github.com/coder/coder/codersdk" | ||
"github.com/coder/coder/provisionersdk" | ||
) | ||
|
@@ -142,6 +143,7 @@ func (r *RootCmd) templatePush() *clibase.Cmd { | |
provisionerTags []string | ||
uploadFlags templateUploadFlags | ||
activate bool | ||
create bool | ||
) | ||
client := new(codersdk.Client) | ||
cmd := &clibase.Cmd{ | ||
|
@@ -164,24 +166,33 @@ func (r *RootCmd) templatePush() *clibase.Cmd { | |
return err | ||
} | ||
|
||
template, err := client.TemplateByName(inv.Context(), organization.ID, name) | ||
resp, err := uploadFlags.upload(inv, client) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = uploadFlags.checkForLockfile(inv) | ||
if err != nil { | ||
return xerrors.Errorf("check for lockfile: %w", err) | ||
} | ||
|
||
resp, err := uploadFlags.upload(inv, client) | ||
tags, err := ParseProvisionerTags(provisionerTags) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
tags, err := ParseProvisionerTags(provisionerTags) | ||
template, err := client.TemplateByName(inv.Context(), organization.ID, name) | ||
if err != nil { | ||
return err | ||
if !create { | ||
_, _ = fmt.Fprintf(inv.Stdout, "Create a new template with `coder templates create %s`.\n", name) | ||
_, _ = fmt.Fprintf(inv.Stdout, "Or use `coder templates push %s --create`.\n", name) | ||
return xerrors.Errorf("template %q not found: %w", name, err) | ||
} | ||
_, _ = fmt.Fprintf(inv.Stdout, "Creating a new template: %s\n", name) | ||
defaultTTL := 24 * time.Hour | ||
failureTTL := 0 * time.Hour | ||
inactivityTTL := 0 * time.Hour | ||
disableEveryone := false | ||
createReq := codersdk.CreateTemplateRequest{Name: name, DefaultTTLMillis: ptr.Ref(defaultTTL.Milliseconds()), FailureTTLMillis: ptr.Ref(failureTTL.Milliseconds()), InactivityTTLMillis: ptr.Ref(inactivityTTL.Milliseconds()), DisableEveryoneGroupAccess: disableEveryone} | ||
template, err = client.CreateTemplate(inv.Context(), organization.ID, createReq) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line specifically. The object There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing CreateTemplateRequest.VersionID - creating a template requires a template version to be present. |
||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
job, err := createValidTemplateVersion(inv, createValidTemplateVersionArgs{ | ||
|
@@ -212,7 +223,6 @@ func (r *RootCmd) templatePush() *clibase.Cmd { | |
return err | ||
} | ||
} | ||
|
||
_, _ = fmt.Fprintf(inv.Stdout, "Updated version at %s!\n", cliui.DefaultStyles.DateTimeStamp.Render(time.Now().Format(time.Stamp))) | ||
return nil | ||
}, | ||
|
@@ -266,6 +276,12 @@ func (r *RootCmd) templatePush() *clibase.Cmd { | |
Default: "true", | ||
Value: clibase.BoolOf(&activate), | ||
}, | ||
{ | ||
Flag: "create", | ||
Description: "Create a new template if one does not already exist.", | ||
Default: "false", | ||
Value: clibase.BoolOf(&create), | ||
}, | ||
cliui.SkipPromptOption(), | ||
} | ||
cmd.Options = append(cmd.Options, uploadFlags.options()...) | ||
|
Uh oh!
There was an error while loading. Please reload this page.