mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore(cli): replace clibase with external coder/serpent (#12252)
This commit is contained in:
+26
-26
@@ -9,13 +9,13 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/pretty"
|
||||
"github.com/coder/serpent"
|
||||
|
||||
"github.com/coder/coder/v2/cli/clibase"
|
||||
"github.com/coder/coder/v2/cli/cliui"
|
||||
"github.com/coder/coder/v2/codersdk"
|
||||
)
|
||||
|
||||
func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
func (r *RootCmd) templateEdit() *serpent.Cmd {
|
||||
const deprecatedFlagName = "deprecated"
|
||||
var (
|
||||
name string
|
||||
@@ -40,14 +40,14 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
)
|
||||
client := new(codersdk.Client)
|
||||
|
||||
cmd := &clibase.Cmd{
|
||||
cmd := &serpent.Cmd{
|
||||
Use: "edit <template>",
|
||||
Middleware: clibase.Chain(
|
||||
clibase.RequireNArgs(1),
|
||||
Middleware: serpent.Chain(
|
||||
serpent.RequireNArgs(1),
|
||||
r.InitClient(client),
|
||||
),
|
||||
Short: "Edit the metadata of a template by name.",
|
||||
Handler: func(inv *clibase.Invocation) error {
|
||||
Handler: func(inv *serpent.Invocation) error {
|
||||
unsetAutostopRequirementDaysOfWeek := len(autostopRequirementDaysOfWeek) == 1 && autostopRequirementDaysOfWeek[0] == "none"
|
||||
requiresScheduling := (len(autostopRequirementDaysOfWeek) > 0 && !unsetAutostopRequirementDaysOfWeek) ||
|
||||
autostopRequirementWeeks > 0 ||
|
||||
@@ -207,53 +207,53 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Options = clibase.OptionSet{
|
||||
cmd.Options = serpent.OptionSet{
|
||||
{
|
||||
Flag: "name",
|
||||
Description: "Edit the template name.",
|
||||
Value: clibase.StringOf(&name),
|
||||
Value: serpent.StringOf(&name),
|
||||
},
|
||||
{
|
||||
Flag: "display-name",
|
||||
Description: "Edit the template display name.",
|
||||
Value: clibase.StringOf(&displayName),
|
||||
Value: serpent.StringOf(&displayName),
|
||||
},
|
||||
{
|
||||
Flag: "description",
|
||||
Description: "Edit the template description.",
|
||||
Value: clibase.StringOf(&description),
|
||||
Value: serpent.StringOf(&description),
|
||||
},
|
||||
{
|
||||
Name: deprecatedFlagName,
|
||||
Flag: "deprecated",
|
||||
Description: "Sets the template as deprecated. Must be a message explaining why the template is deprecated.",
|
||||
Value: clibase.StringOf(&deprecationMessage),
|
||||
Value: serpent.StringOf(&deprecationMessage),
|
||||
},
|
||||
{
|
||||
Flag: "icon",
|
||||
Description: "Edit the template icon path.",
|
||||
Value: clibase.StringOf(&icon),
|
||||
Value: serpent.StringOf(&icon),
|
||||
},
|
||||
{
|
||||
Flag: "default-ttl",
|
||||
Description: "Edit the template default time before shutdown - workspaces created from this template default to this value. Maps to \"Default autostop\" in the UI.",
|
||||
Value: clibase.DurationOf(&defaultTTL),
|
||||
Value: serpent.DurationOf(&defaultTTL),
|
||||
},
|
||||
{
|
||||
Flag: "activity-bump",
|
||||
Description: "Edit the template activity bump - workspaces created from this template will have their shutdown time bumped by this value when activity is detected. Maps to \"Activity bump\" in the UI.",
|
||||
Value: clibase.DurationOf(&activityBump),
|
||||
Value: serpent.DurationOf(&activityBump),
|
||||
},
|
||||
{
|
||||
Flag: "max-ttl",
|
||||
Description: "Edit the template maximum time before shutdown - workspaces created from this template must shutdown within the given duration after starting, regardless of user activity. This is an enterprise-only feature. Maps to \"Max lifetime\" in the UI.",
|
||||
Value: clibase.DurationOf(&maxTTL),
|
||||
Value: serpent.DurationOf(&maxTTL),
|
||||
},
|
||||
{
|
||||
Flag: "autostart-requirement-weekdays",
|
||||
// workspaces created from this template must be restarted on the given weekdays. To unset this value for the template (and disable the autostop requirement for the template), pass 'none'.
|
||||
Description: "Edit the template autostart requirement weekdays - workspaces created from this template can only autostart on the given weekdays. To unset this value for the template (and allow autostart on all days), pass 'all'.",
|
||||
Value: clibase.Validate(clibase.StringArrayOf(&autostartRequirementDaysOfWeek), func(value *clibase.StringArray) error {
|
||||
Value: serpent.Validate(serpent.StringArrayOf(&autostartRequirementDaysOfWeek), func(value *serpent.StringArray) error {
|
||||
v := value.GetSlice()
|
||||
if len(v) == 1 && v[0] == "all" {
|
||||
return nil
|
||||
@@ -270,7 +270,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
Description: "Edit the template autostop requirement weekdays - workspaces created from this template must be restarted on the given weekdays. To unset this value for the template (and disable the autostop requirement for the template), pass 'none'.",
|
||||
// TODO(@dean): unhide when we delete max_ttl
|
||||
Hidden: true,
|
||||
Value: clibase.Validate(clibase.StringArrayOf(&autostopRequirementDaysOfWeek), func(value *clibase.StringArray) error {
|
||||
Value: serpent.Validate(serpent.StringArrayOf(&autostopRequirementDaysOfWeek), func(value *serpent.StringArray) error {
|
||||
v := value.GetSlice()
|
||||
if len(v) == 1 && v[0] == "none" {
|
||||
return nil
|
||||
@@ -287,55 +287,55 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
|
||||
Description: "Edit the template autostop requirement weeks - workspaces created from this template must be restarted on an n-weekly basis.",
|
||||
// TODO(@dean): unhide when we delete max_ttl
|
||||
Hidden: true,
|
||||
Value: clibase.Int64Of(&autostopRequirementWeeks),
|
||||
Value: serpent.Int64Of(&autostopRequirementWeeks),
|
||||
},
|
||||
{
|
||||
Flag: "failure-ttl",
|
||||
Description: "Specify a failure TTL for workspaces created from this template. It is the amount of time after a failed \"start\" build before coder automatically schedules a \"stop\" build to cleanup.This licensed feature's default is 0h (off). Maps to \"Failure cleanup\" in the UI.",
|
||||
Default: "0h",
|
||||
Value: clibase.DurationOf(&failureTTL),
|
||||
Value: serpent.DurationOf(&failureTTL),
|
||||
},
|
||||
{
|
||||
Flag: "dormancy-threshold",
|
||||
Description: "Specify a duration workspaces may be inactive prior to being moved to the dormant state. This licensed feature's default is 0h (off). Maps to \"Dormancy threshold\" in the UI.",
|
||||
Default: "0h",
|
||||
Value: clibase.DurationOf(&dormancyThreshold),
|
||||
Value: serpent.DurationOf(&dormancyThreshold),
|
||||
},
|
||||
{
|
||||
Flag: "dormancy-auto-deletion",
|
||||
Description: "Specify a duration workspaces may be in the dormant state prior to being deleted. This licensed feature's default is 0h (off). Maps to \"Dormancy Auto-Deletion\" in the UI.",
|
||||
Default: "0h",
|
||||
Value: clibase.DurationOf(&dormancyAutoDeletion),
|
||||
Value: serpent.DurationOf(&dormancyAutoDeletion),
|
||||
},
|
||||
{
|
||||
Flag: "allow-user-cancel-workspace-jobs",
|
||||
Description: "Allow users to cancel in-progress workspace jobs.",
|
||||
Default: "true",
|
||||
Value: clibase.BoolOf(&allowUserCancelWorkspaceJobs),
|
||||
Value: serpent.BoolOf(&allowUserCancelWorkspaceJobs),
|
||||
},
|
||||
{
|
||||
Flag: "allow-user-autostart",
|
||||
Description: "Allow users to configure autostart for workspaces on this template. This can only be disabled in enterprise.",
|
||||
Default: "true",
|
||||
Value: clibase.BoolOf(&allowUserAutostart),
|
||||
Value: serpent.BoolOf(&allowUserAutostart),
|
||||
},
|
||||
{
|
||||
Flag: "allow-user-autostop",
|
||||
Description: "Allow users to customize the autostop TTL for workspaces on this template. This can only be disabled in enterprise.",
|
||||
Default: "true",
|
||||
Value: clibase.BoolOf(&allowUserAutostop),
|
||||
Value: serpent.BoolOf(&allowUserAutostop),
|
||||
},
|
||||
{
|
||||
Flag: "require-active-version",
|
||||
Description: "Requires workspace builds to use the active template version. This setting does not apply to template admins. This is an enterprise-only feature.",
|
||||
Value: clibase.BoolOf(&requireActiveVersion),
|
||||
Value: serpent.BoolOf(&requireActiveVersion),
|
||||
Default: "false",
|
||||
},
|
||||
{
|
||||
Flag: "private",
|
||||
Description: "Disable the default behavior of granting template access to the 'everyone' group. " +
|
||||
"The template permissions must be updated to allow non-admin users to use this template.",
|
||||
Value: clibase.BoolOf(&disableEveryone),
|
||||
Value: serpent.BoolOf(&disableEveryone),
|
||||
Default: "false",
|
||||
},
|
||||
cliui.SkipPromptOption(),
|
||||
|
||||
Reference in New Issue
Block a user