Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2b5009

Browse files
authored
fix: Unnest workspaces command to the top-level (#1241)
This changes all "coder workspace *" commands to root. A few of these were already at the root, like SSH. The inconsistency made for a confusing experience.
1 parent 252d868 commit c2b5009

20 files changed

+75
-124
lines changed

cli/workspaceautostart.go renamed to cli/autostart.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,30 @@ When enabling autostart, provide the minute, hour, and day(s) of week.
1616
The default schedule is at 09:00 in your local timezone (TZ env, UTC by default).
1717
`
1818

19-
func workspaceAutostart() *cobra.Command {
19+
func autostart() *cobra.Command {
2020
autostartCmd := &cobra.Command{
2121
Use: "autostart enable <workspace>",
2222
Short: "schedule a workspace to automatically start at a regular time",
2323
Long: autostartDescriptionLong,
24-
Example: "coder workspaces autostart enable my-workspace --minute 30 --hour 9 --days 1-5 --tz Europe/Dublin",
24+
Example: "coder autostart enable my-workspace --minute 30 --hour 9 --days 1-5 --tz Europe/Dublin",
2525
Hidden: true,
2626
}
2727

28-
autostartCmd.AddCommand(workspaceAutostartEnable())
29-
autostartCmd.AddCommand(workspaceAutostartDisable())
28+
autostartCmd.AddCommand(autostartEnable())
29+
autostartCmd.AddCommand(autostartDisable())
3030

3131
return autostartCmd
3232
}
3333

34-
func workspaceAutostartEnable() *cobra.Command {
34+
func autostartEnable() *cobra.Command {
3535
// yes some of these are technically numbers but the cron library will do that work
3636
var autostartMinute string
3737
var autostartHour string
3838
var autostartDayOfWeek string
3939
var autostartTimezone string
4040
cmd := &cobra.Command{
41-
Use: "enable <workspace_name> <schedule>",
42-
ValidArgsFunction: validArgsWorkspaceName,
43-
Args: cobra.ExactArgs(1),
41+
Use: "enable <workspace_name> <schedule>",
42+
Args: cobra.ExactArgs(1),
4443
RunE: func(cmd *cobra.Command, args []string) error {
4544
client, err := createClient(cmd)
4645
if err != nil {
@@ -86,11 +85,10 @@ func workspaceAutostartEnable() *cobra.Command {
8685
return cmd
8786
}
8887

89-
func workspaceAutostartDisable() *cobra.Command {
88+
func autostartDisable() *cobra.Command {
9089
return &cobra.Command{
91-
Use: "disable <workspace_name>",
92-
ValidArgsFunction: validArgsWorkspaceName,
93-
Args: cobra.ExactArgs(1),
90+
Use: "disable <workspace_name>",
91+
Args: cobra.ExactArgs(1),
9492
RunE: func(cmd *cobra.Command, args []string) error {
9593
client, err := createClient(cmd)
9694
if err != nil {

cli/workspaceautostart_test.go renamed to cli/autostart_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/coder/coder/coderd/coderdtest"
1414
)
1515

16-
func TestWorkspaceAutostart(t *testing.T) {
16+
func TestAutostart(t *testing.T) {
1717
t.Parallel()
1818

1919
t.Run("EnableDisableOK", func(t *testing.T) {
@@ -29,7 +29,7 @@ func TestWorkspaceAutostart(t *testing.T) {
2929
project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
3030
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID)
3131
tz = "Europe/Dublin"
32-
cmdArgs = []string{"workspaces", "autostart", "enable", workspace.Name, "--minute", "30", "--hour", "9", "--days", "1-5", "--tz", tz}
32+
cmdArgs = []string{"autostart", "enable", workspace.Name, "--minute", "30", "--hour", "9", "--days", "1-5", "--tz", tz}
3333
sched = "CRON_TZ=Europe/Dublin 30 9 * * 1-5"
3434
stdoutBuf = &bytes.Buffer{}
3535
)
@@ -48,7 +48,7 @@ func TestWorkspaceAutostart(t *testing.T) {
4848
require.Equal(t, sched, updated.AutostartSchedule, "expected autostart schedule to be set")
4949

5050
// Disable schedule
51-
cmd, root = clitest.New(t, "workspaces", "autostart", "disable", workspace.Name)
51+
cmd, root = clitest.New(t, "autostart", "disable", workspace.Name)
5252
clitest.SetupConfig(t, client, root)
5353
cmd.SetOut(stdoutBuf)
5454

@@ -73,7 +73,7 @@ func TestWorkspaceAutostart(t *testing.T) {
7373
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
7474
)
7575

76-
cmd, root := clitest.New(t, "workspaces", "autostart", "enable", "doesnotexist")
76+
cmd, root := clitest.New(t, "autostart", "enable", "doesnotexist")
7777
clitest.SetupConfig(t, client, root)
7878

7979
err := cmd.Execute()
@@ -91,7 +91,7 @@ func TestWorkspaceAutostart(t *testing.T) {
9191
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
9292
)
9393

94-
cmd, root := clitest.New(t, "workspaces", "autostart", "disable", "doesnotexist")
94+
cmd, root := clitest.New(t, "autostart", "disable", "doesnotexist")
9595
clitest.SetupConfig(t, client, root)
9696

9797
err := cmd.Execute()
@@ -118,7 +118,7 @@ func TestWorkspaceAutostart(t *testing.T) {
118118
currTz = "UTC"
119119
}
120120
expectedSchedule := fmt.Sprintf("CRON_TZ=%s 0 9 * * 1-5", currTz)
121-
cmd, root := clitest.New(t, "workspaces", "autostart", "enable", workspace.Name)
121+
cmd, root := clitest.New(t, "autostart", "enable", workspace.Name)
122122
clitest.SetupConfig(t, client, root)
123123

124124
err := cmd.Execute()

cli/workspaceautostop.go renamed to cli/autostop.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,30 @@ When enabling autostop, provide the minute, hour, and day(s) of week.
1616
The default autostop schedule is at 18:00 in your local timezone (TZ env, UTC by default).
1717
`
1818

19-
func workspaceAutostop() *cobra.Command {
19+
func autostop() *cobra.Command {
2020
autostopCmd := &cobra.Command{
2121
Use: "autostop enable <workspace>",
2222
Short: "schedule a workspace to automatically stop at a regular time",
2323
Long: autostopDescriptionLong,
24-
Example: "coder workspaces autostop enable my-workspace --minute 0 --hour 18 --days 1-5 -tz Europe/Dublin",
24+
Example: "coder autostop enable my-workspace --minute 0 --hour 18 --days 1-5 -tz Europe/Dublin",
2525
Hidden: true,
2626
}
2727

28-
autostopCmd.AddCommand(workspaceAutostopEnable())
29-
autostopCmd.AddCommand(workspaceAutostopDisable())
28+
autostopCmd.AddCommand(autostopEnable())
29+
autostopCmd.AddCommand(autostopDisable())
3030

3131
return autostopCmd
3232
}
3333

34-
func workspaceAutostopEnable() *cobra.Command {
34+
func autostopEnable() *cobra.Command {
3535
// yes some of these are technically numbers but the cron library will do that work
3636
var autostopMinute string
3737
var autostopHour string
3838
var autostopDayOfWeek string
3939
var autostopTimezone string
4040
cmd := &cobra.Command{
41-
Use: "enable <workspace_name> <schedule>",
42-
ValidArgsFunction: validArgsWorkspaceName,
43-
Args: cobra.ExactArgs(1),
41+
Use: "enable <workspace_name> <schedule>",
42+
Args: cobra.ExactArgs(1),
4443
RunE: func(cmd *cobra.Command, args []string) error {
4544
client, err := createClient(cmd)
4645
if err != nil {
@@ -86,11 +85,10 @@ func workspaceAutostopEnable() *cobra.Command {
8685
return cmd
8786
}
8887

89-
func workspaceAutostopDisable() *cobra.Command {
88+
func autostopDisable() *cobra.Command {
9089
return &cobra.Command{
91-
Use: "disable <workspace_name>",
92-
ValidArgsFunction: validArgsWorkspaceName,
93-
Args: cobra.ExactArgs(1),
90+
Use: "disable <workspace_name>",
91+
Args: cobra.ExactArgs(1),
9492
RunE: func(cmd *cobra.Command, args []string) error {
9593
client, err := createClient(cmd)
9694
if err != nil {

cli/workspaceautostop_test.go renamed to cli/autostop_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/coder/coder/coderd/coderdtest"
1414
)
1515

16-
func TestWorkspaceAutostop(t *testing.T) {
16+
func TestAutostop(t *testing.T) {
1717
t.Parallel()
1818

1919
t.Run("EnableDisableOK", func(t *testing.T) {
@@ -28,7 +28,7 @@ func TestWorkspaceAutostop(t *testing.T) {
2828
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
2929
project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
3030
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID)
31-
cmdArgs = []string{"workspaces", "autostop", "enable", workspace.Name, "--minute", "30", "--hour", "17", "--days", "1-5", "--tz", "Europe/Dublin"}
31+
cmdArgs = []string{"autostop", "enable", workspace.Name, "--minute", "30", "--hour", "17", "--days", "1-5", "--tz", "Europe/Dublin"}
3232
sched = "CRON_TZ=Europe/Dublin 30 17 * * 1-5"
3333
stdoutBuf = &bytes.Buffer{}
3434
)
@@ -47,7 +47,7 @@ func TestWorkspaceAutostop(t *testing.T) {
4747
require.Equal(t, sched, updated.AutostopSchedule, "expected autostop schedule to be set")
4848

4949
// Disable schedule
50-
cmd, root = clitest.New(t, "workspaces", "autostop", "disable", workspace.Name)
50+
cmd, root = clitest.New(t, "autostop", "disable", workspace.Name)
5151
clitest.SetupConfig(t, client, root)
5252
cmd.SetOut(stdoutBuf)
5353

@@ -72,7 +72,7 @@ func TestWorkspaceAutostop(t *testing.T) {
7272
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
7373
)
7474

75-
cmd, root := clitest.New(t, "workspaces", "autostop", "enable", "doesnotexist")
75+
cmd, root := clitest.New(t, "autostop", "enable", "doesnotexist")
7676
clitest.SetupConfig(t, client, root)
7777

7878
err := cmd.Execute()
@@ -90,7 +90,7 @@ func TestWorkspaceAutostop(t *testing.T) {
9090
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
9191
)
9292

93-
cmd, root := clitest.New(t, "workspaces", "autostop", "disable", "doesnotexist")
93+
cmd, root := clitest.New(t, "autostop", "disable", "doesnotexist")
9494
clitest.SetupConfig(t, client, root)
9595

9696
err := cmd.Execute()
@@ -118,7 +118,7 @@ func TestWorkspaceAutostop(t *testing.T) {
118118
}
119119
expectedSchedule := fmt.Sprintf("CRON_TZ=%s 0 18 * * 1-5", currTz)
120120

121-
cmd, root := clitest.New(t, "workspaces", "autostop", "enable", workspace.Name)
121+
cmd, root := clitest.New(t, "autostop", "enable", workspace.Name)
122122
clitest.SetupConfig(t, client, root)
123123

124124
err := cmd.Execute()

cli/cliui/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
6060
defer resourceMutex.Unlock()
6161
message := "Don't panic, your workspace is booting up!"
6262
if agent.Status == codersdk.WorkspaceAgentDisconnected {
63-
message = "The workspace agent lost connection! Wait for it to reconnect or run: " + Styles.Code.Render("coder workspaces rebuild "+opts.WorkspaceName)
63+
message = "The workspace agent lost connection! Wait for it to reconnect or run: " + Styles.Code.Render("coder rebuild "+opts.WorkspaceName)
6464
}
6565
// This saves the cursor position, then defers clearing from the cursor
6666
// position to the end of the screen.

cli/workspacecreate.go renamed to cli/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/coder/coder/codersdk"
1515
)
1616

17-
func workspaceCreate() *cobra.Command {
17+
func create() *cobra.Command {
1818
var (
1919
workspaceName string
2020
templateName string

cli/workspacecreate_test.go renamed to cli/create_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/coder/coder/pty/ptytest"
1313
)
1414

15-
func TestWorkspaceCreate(t *testing.T) {
15+
func TestCreate(t *testing.T) {
1616
t.Parallel()
1717
t.Run("Create", func(t *testing.T) {
1818
t.Parallel()
@@ -22,7 +22,7 @@ func TestWorkspaceCreate(t *testing.T) {
2222
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
2323
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
2424
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
25-
cmd, root := clitest.New(t, "workspaces", "create", "my-workspace", "--template", template.Name)
25+
cmd, root := clitest.New(t, "create", "my-workspace", "--template", template.Name)
2626
clitest.SetupConfig(t, client, root)
2727
doneChan := make(chan struct{})
2828
pty := ptytest.New(t)
@@ -52,7 +52,7 @@ func TestWorkspaceCreate(t *testing.T) {
5252
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
5353
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
5454
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
55-
cmd, root := clitest.New(t, "workspaces", "create", "my-workspace")
55+
cmd, root := clitest.New(t, "create", "my-workspace")
5656
clitest.SetupConfig(t, client, root)
5757
doneChan := make(chan struct{})
5858
pty := ptytest.New(t)
@@ -82,7 +82,7 @@ func TestWorkspaceCreate(t *testing.T) {
8282
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
8383
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
8484
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
85-
cmd, root := clitest.New(t, "workspaces", "create", "")
85+
cmd, root := clitest.New(t, "create", "")
8686
clitest.SetupConfig(t, client, root)
8787
doneChan := make(chan struct{})
8888
pty := ptytest.New(t)
@@ -134,7 +134,7 @@ func TestWorkspaceCreate(t *testing.T) {
134134
})
135135
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
136136
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
137-
cmd, root := clitest.New(t, "workspaces", "create", "")
137+
cmd, root := clitest.New(t, "create", "")
138138
clitest.SetupConfig(t, client, root)
139139
doneChan := make(chan struct{})
140140
pty := ptytest.New(t)

cli/workspacedelete.go renamed to cli/delete.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"github.com/coder/coder/codersdk"
1111
)
1212

13-
func workspaceDelete() *cobra.Command {
13+
// nolint
14+
func delete() *cobra.Command {
1415
return &cobra.Command{
15-
Use: "delete <workspace>",
16-
Aliases: []string{"rm"},
17-
ValidArgsFunction: validArgsWorkspaceName,
18-
Args: cobra.ExactArgs(1),
16+
Use: "delete <workspace>",
17+
Aliases: []string{"rm"},
18+
Args: cobra.ExactArgs(1),
1919
RunE: func(cmd *cobra.Command, args []string) error {
2020
client, err := createClient(cmd)
2121
if err != nil {

cli/workspacelist.go renamed to cli/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/coder/coder/codersdk"
1212
)
1313

14-
func workspaceList() *cobra.Command {
14+
func list() *cobra.Command {
1515
return &cobra.Command{
1616
Use: "list",
1717
Aliases: []string{"ls"},
@@ -31,7 +31,7 @@ func workspaceList() *cobra.Command {
3131
if len(workspaces) == 0 {
3232
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"No workspaces found! Create one:")
3333
_, _ = fmt.Fprintln(cmd.OutOrStdout())
34-
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render("coder workspaces create <name>"))
34+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render("coder create <name>"))
3535
_, _ = fmt.Fprintln(cmd.OutOrStdout())
3636
return nil
3737
}

cli/root.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,25 @@ func Root() *cobra.Command {
6767
cmd.SetVersionTemplate(versionTemplate())
6868

6969
cmd.AddCommand(
70+
autostart(),
71+
autostop(),
7072
configSSH(),
71-
server(),
73+
create(),
74+
delete(),
75+
gitssh(),
76+
list(),
7277
login(),
7378
parameters(),
79+
publickey(),
80+
server(),
81+
show(),
82+
start(),
83+
stop(),
84+
ssh(),
7485
templates(),
86+
update(),
7587
users(),
76-
workspaces(),
77-
ssh(),
78-
workspaceTunnel(),
79-
gitssh(),
80-
publickey(),
88+
tunnel(),
8189
workspaceAgent(),
8290
)
8391

cli/workspaceshow.go renamed to cli/show.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/coder/coder/codersdk"
99
)
1010

11-
func workspaceShow() *cobra.Command {
11+
func show() *cobra.Command {
1212
return &cobra.Command{
1313
Use: "show",
1414
Args: cobra.ExactArgs(1),

cli/workspacestart.go renamed to cli/start.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import (
1010
"github.com/coder/coder/codersdk"
1111
)
1212

13-
func workspaceStart() *cobra.Command {
13+
func start() *cobra.Command {
1414
return &cobra.Command{
15-
Use: "start <workspace>",
16-
ValidArgsFunction: validArgsWorkspaceName,
17-
Args: cobra.ExactArgs(1),
15+
Use: "start <workspace>",
16+
Args: cobra.ExactArgs(1),
1817
RunE: func(cmd *cobra.Command, args []string) error {
1918
client, err := createClient(cmd)
2019
if err != nil {

cli/workspacestop.go renamed to cli/stop.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import (
1010
"github.com/coder/coder/codersdk"
1111
)
1212

13-
func workspaceStop() *cobra.Command {
13+
func stop() *cobra.Command {
1414
return &cobra.Command{
15-
Use: "stop <workspace>",
16-
ValidArgsFunction: validArgsWorkspaceName,
17-
Args: cobra.ExactArgs(1),
15+
Use: "stop <workspace>",
16+
Args: cobra.ExactArgs(1),
1817
RunE: func(cmd *cobra.Command, args []string) error {
1918
client, err := createClient(cmd)
2019
if err != nil {

cli/templatecreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func templateCreate() *cobra.Command {
115115
"The "+cliui.Styles.Keyword.Render(templateName)+" template has been created! "+
116116
"Developers can provision a workspace with this template using:")+"\n")
117117

118-
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render(fmt.Sprintf("coder workspaces create --template=%q [workspace name]", templateName)))
118+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render(fmt.Sprintf("coder create --template=%q [workspace name]", templateName)))
119119
_, _ = fmt.Fprintln(cmd.OutOrStdout())
120120

121121
return nil

0 commit comments

Comments
 (0)