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.
This commit is contained in:
Kyle Carberry
2022-05-02 11:08:52 -05:00
committed by GitHub
parent 252d868298
commit c2b5009208
20 changed files with 76 additions and 125 deletions

View File

@ -16,31 +16,30 @@ When enabling autostart, provide the minute, hour, and day(s) of week.
The default schedule is at 09:00 in your local timezone (TZ env, UTC by default). The default schedule is at 09:00 in your local timezone (TZ env, UTC by default).
` `
func workspaceAutostart() *cobra.Command { func autostart() *cobra.Command {
autostartCmd := &cobra.Command{ autostartCmd := &cobra.Command{
Use: "autostart enable <workspace>", Use: "autostart enable <workspace>",
Short: "schedule a workspace to automatically start at a regular time", Short: "schedule a workspace to automatically start at a regular time",
Long: autostartDescriptionLong, Long: autostartDescriptionLong,
Example: "coder workspaces autostart enable my-workspace --minute 30 --hour 9 --days 1-5 --tz Europe/Dublin", Example: "coder autostart enable my-workspace --minute 30 --hour 9 --days 1-5 --tz Europe/Dublin",
Hidden: true, Hidden: true,
} }
autostartCmd.AddCommand(workspaceAutostartEnable()) autostartCmd.AddCommand(autostartEnable())
autostartCmd.AddCommand(workspaceAutostartDisable()) autostartCmd.AddCommand(autostartDisable())
return autostartCmd return autostartCmd
} }
func workspaceAutostartEnable() *cobra.Command { func autostartEnable() *cobra.Command {
// yes some of these are technically numbers but the cron library will do that work // yes some of these are technically numbers but the cron library will do that work
var autostartMinute string var autostartMinute string
var autostartHour string var autostartHour string
var autostartDayOfWeek string var autostartDayOfWeek string
var autostartTimezone string var autostartTimezone string
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "enable <workspace_name> <schedule>", Use: "enable <workspace_name> <schedule>",
ValidArgsFunction: validArgsWorkspaceName, Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd) client, err := createClient(cmd)
if err != nil { if err != nil {
@ -86,11 +85,10 @@ func workspaceAutostartEnable() *cobra.Command {
return cmd return cmd
} }
func workspaceAutostartDisable() *cobra.Command { func autostartDisable() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "disable <workspace_name>", Use: "disable <workspace_name>",
ValidArgsFunction: validArgsWorkspaceName, Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd) client, err := createClient(cmd)
if err != nil { if err != nil {

View File

@ -13,7 +13,7 @@ import (
"github.com/coder/coder/coderd/coderdtest" "github.com/coder/coder/coderd/coderdtest"
) )
func TestWorkspaceAutostart(t *testing.T) { func TestAutostart(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("EnableDisableOK", func(t *testing.T) { t.Run("EnableDisableOK", func(t *testing.T) {
@ -29,7 +29,7 @@ func TestWorkspaceAutostart(t *testing.T) {
project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID) workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID)
tz = "Europe/Dublin" tz = "Europe/Dublin"
cmdArgs = []string{"workspaces", "autostart", "enable", workspace.Name, "--minute", "30", "--hour", "9", "--days", "1-5", "--tz", tz} cmdArgs = []string{"autostart", "enable", workspace.Name, "--minute", "30", "--hour", "9", "--days", "1-5", "--tz", tz}
sched = "CRON_TZ=Europe/Dublin 30 9 * * 1-5" sched = "CRON_TZ=Europe/Dublin 30 9 * * 1-5"
stdoutBuf = &bytes.Buffer{} stdoutBuf = &bytes.Buffer{}
) )
@ -48,7 +48,7 @@ func TestWorkspaceAutostart(t *testing.T) {
require.Equal(t, sched, updated.AutostartSchedule, "expected autostart schedule to be set") require.Equal(t, sched, updated.AutostartSchedule, "expected autostart schedule to be set")
// Disable schedule // Disable schedule
cmd, root = clitest.New(t, "workspaces", "autostart", "disable", workspace.Name) cmd, root = clitest.New(t, "autostart", "disable", workspace.Name)
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
cmd.SetOut(stdoutBuf) cmd.SetOut(stdoutBuf)
@ -73,7 +73,7 @@ func TestWorkspaceAutostart(t *testing.T) {
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID) _ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
) )
cmd, root := clitest.New(t, "workspaces", "autostart", "enable", "doesnotexist") cmd, root := clitest.New(t, "autostart", "enable", "doesnotexist")
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
err := cmd.Execute() err := cmd.Execute()
@ -91,7 +91,7 @@ func TestWorkspaceAutostart(t *testing.T) {
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID) _ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
) )
cmd, root := clitest.New(t, "workspaces", "autostart", "disable", "doesnotexist") cmd, root := clitest.New(t, "autostart", "disable", "doesnotexist")
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
err := cmd.Execute() err := cmd.Execute()
@ -118,7 +118,7 @@ func TestWorkspaceAutostart(t *testing.T) {
currTz = "UTC" currTz = "UTC"
} }
expectedSchedule := fmt.Sprintf("CRON_TZ=%s 0 9 * * 1-5", currTz) expectedSchedule := fmt.Sprintf("CRON_TZ=%s 0 9 * * 1-5", currTz)
cmd, root := clitest.New(t, "workspaces", "autostart", "enable", workspace.Name) cmd, root := clitest.New(t, "autostart", "enable", workspace.Name)
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
err := cmd.Execute() err := cmd.Execute()

View File

@ -16,31 +16,30 @@ When enabling autostop, provide the minute, hour, and day(s) of week.
The default autostop schedule is at 18:00 in your local timezone (TZ env, UTC by default). The default autostop schedule is at 18:00 in your local timezone (TZ env, UTC by default).
` `
func workspaceAutostop() *cobra.Command { func autostop() *cobra.Command {
autostopCmd := &cobra.Command{ autostopCmd := &cobra.Command{
Use: "autostop enable <workspace>", Use: "autostop enable <workspace>",
Short: "schedule a workspace to automatically stop at a regular time", Short: "schedule a workspace to automatically stop at a regular time",
Long: autostopDescriptionLong, Long: autostopDescriptionLong,
Example: "coder workspaces autostop enable my-workspace --minute 0 --hour 18 --days 1-5 -tz Europe/Dublin", Example: "coder autostop enable my-workspace --minute 0 --hour 18 --days 1-5 -tz Europe/Dublin",
Hidden: true, Hidden: true,
} }
autostopCmd.AddCommand(workspaceAutostopEnable()) autostopCmd.AddCommand(autostopEnable())
autostopCmd.AddCommand(workspaceAutostopDisable()) autostopCmd.AddCommand(autostopDisable())
return autostopCmd return autostopCmd
} }
func workspaceAutostopEnable() *cobra.Command { func autostopEnable() *cobra.Command {
// yes some of these are technically numbers but the cron library will do that work // yes some of these are technically numbers but the cron library will do that work
var autostopMinute string var autostopMinute string
var autostopHour string var autostopHour string
var autostopDayOfWeek string var autostopDayOfWeek string
var autostopTimezone string var autostopTimezone string
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "enable <workspace_name> <schedule>", Use: "enable <workspace_name> <schedule>",
ValidArgsFunction: validArgsWorkspaceName, Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd) client, err := createClient(cmd)
if err != nil { if err != nil {
@ -86,11 +85,10 @@ func workspaceAutostopEnable() *cobra.Command {
return cmd return cmd
} }
func workspaceAutostopDisable() *cobra.Command { func autostopDisable() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "disable <workspace_name>", Use: "disable <workspace_name>",
ValidArgsFunction: validArgsWorkspaceName, Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd) client, err := createClient(cmd)
if err != nil { if err != nil {

View File

@ -13,7 +13,7 @@ import (
"github.com/coder/coder/coderd/coderdtest" "github.com/coder/coder/coderd/coderdtest"
) )
func TestWorkspaceAutostop(t *testing.T) { func TestAutostop(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("EnableDisableOK", func(t *testing.T) { t.Run("EnableDisableOK", func(t *testing.T) {
@ -28,7 +28,7 @@ func TestWorkspaceAutostop(t *testing.T) {
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID) _ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) project = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID) workspace = coderdtest.CreateWorkspace(t, client, user.OrganizationID, project.ID)
cmdArgs = []string{"workspaces", "autostop", "enable", workspace.Name, "--minute", "30", "--hour", "17", "--days", "1-5", "--tz", "Europe/Dublin"} cmdArgs = []string{"autostop", "enable", workspace.Name, "--minute", "30", "--hour", "17", "--days", "1-5", "--tz", "Europe/Dublin"}
sched = "CRON_TZ=Europe/Dublin 30 17 * * 1-5" sched = "CRON_TZ=Europe/Dublin 30 17 * * 1-5"
stdoutBuf = &bytes.Buffer{} stdoutBuf = &bytes.Buffer{}
) )
@ -47,7 +47,7 @@ func TestWorkspaceAutostop(t *testing.T) {
require.Equal(t, sched, updated.AutostopSchedule, "expected autostop schedule to be set") require.Equal(t, sched, updated.AutostopSchedule, "expected autostop schedule to be set")
// Disable schedule // Disable schedule
cmd, root = clitest.New(t, "workspaces", "autostop", "disable", workspace.Name) cmd, root = clitest.New(t, "autostop", "disable", workspace.Name)
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
cmd.SetOut(stdoutBuf) cmd.SetOut(stdoutBuf)
@ -72,7 +72,7 @@ func TestWorkspaceAutostop(t *testing.T) {
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID) _ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
) )
cmd, root := clitest.New(t, "workspaces", "autostop", "enable", "doesnotexist") cmd, root := clitest.New(t, "autostop", "enable", "doesnotexist")
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
err := cmd.Execute() err := cmd.Execute()
@ -90,7 +90,7 @@ func TestWorkspaceAutostop(t *testing.T) {
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID) _ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
) )
cmd, root := clitest.New(t, "workspaces", "autostop", "disable", "doesnotexist") cmd, root := clitest.New(t, "autostop", "disable", "doesnotexist")
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
err := cmd.Execute() err := cmd.Execute()
@ -118,7 +118,7 @@ func TestWorkspaceAutostop(t *testing.T) {
} }
expectedSchedule := fmt.Sprintf("CRON_TZ=%s 0 18 * * 1-5", currTz) expectedSchedule := fmt.Sprintf("CRON_TZ=%s 0 18 * * 1-5", currTz)
cmd, root := clitest.New(t, "workspaces", "autostop", "enable", workspace.Name) cmd, root := clitest.New(t, "autostop", "enable", workspace.Name)
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
err := cmd.Execute() err := cmd.Execute()

View File

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

View File

@ -14,7 +14,7 @@ import (
"github.com/coder/coder/codersdk" "github.com/coder/coder/codersdk"
) )
func workspaceCreate() *cobra.Command { func create() *cobra.Command {
var ( var (
workspaceName string workspaceName string
templateName string templateName string

View File

@ -12,7 +12,7 @@ import (
"github.com/coder/coder/pty/ptytest" "github.com/coder/coder/pty/ptytest"
) )
func TestWorkspaceCreate(t *testing.T) { func TestCreate(t *testing.T) {
t.Parallel() t.Parallel()
t.Run("Create", func(t *testing.T) { t.Run("Create", func(t *testing.T) {
t.Parallel() t.Parallel()
@ -22,7 +22,7 @@ func TestWorkspaceCreate(t *testing.T) {
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID) coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
cmd, root := clitest.New(t, "workspaces", "create", "my-workspace", "--template", template.Name) cmd, root := clitest.New(t, "create", "my-workspace", "--template", template.Name)
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{}) doneChan := make(chan struct{})
pty := ptytest.New(t) pty := ptytest.New(t)
@ -52,7 +52,7 @@ func TestWorkspaceCreate(t *testing.T) {
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID) coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) _ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
cmd, root := clitest.New(t, "workspaces", "create", "my-workspace") cmd, root := clitest.New(t, "create", "my-workspace")
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{}) doneChan := make(chan struct{})
pty := ptytest.New(t) pty := ptytest.New(t)
@ -82,7 +82,7 @@ func TestWorkspaceCreate(t *testing.T) {
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil) version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID) coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) _ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
cmd, root := clitest.New(t, "workspaces", "create", "") cmd, root := clitest.New(t, "create", "")
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{}) doneChan := make(chan struct{})
pty := ptytest.New(t) pty := ptytest.New(t)
@ -134,7 +134,7 @@ func TestWorkspaceCreate(t *testing.T) {
}) })
coderdtest.AwaitTemplateVersionJob(t, client, version.ID) coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) _ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
cmd, root := clitest.New(t, "workspaces", "create", "") cmd, root := clitest.New(t, "create", "")
clitest.SetupConfig(t, client, root) clitest.SetupConfig(t, client, root)
doneChan := make(chan struct{}) doneChan := make(chan struct{})
pty := ptytest.New(t) pty := ptytest.New(t)

View File

@ -10,12 +10,12 @@ import (
"github.com/coder/coder/codersdk" "github.com/coder/coder/codersdk"
) )
func workspaceDelete() *cobra.Command { // nolint
func delete() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "delete <workspace>", Use: "delete <workspace>",
Aliases: []string{"rm"}, Aliases: []string{"rm"},
ValidArgsFunction: validArgsWorkspaceName, Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd) client, err := createClient(cmd)
if err != nil { if err != nil {

View File

@ -11,7 +11,7 @@ import (
"github.com/coder/coder/codersdk" "github.com/coder/coder/codersdk"
) )
func workspaceList() *cobra.Command { func list() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "list", Use: "list",
Aliases: []string{"ls"}, Aliases: []string{"ls"},
@ -31,7 +31,7 @@ func workspaceList() *cobra.Command {
if len(workspaces) == 0 { if len(workspaces) == 0 {
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"No workspaces found! Create one:") _, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"No workspaces found! Create one:")
_, _ = fmt.Fprintln(cmd.OutOrStdout()) _, _ = fmt.Fprintln(cmd.OutOrStdout())
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render("coder workspaces create <name>")) _, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render("coder create <name>"))
_, _ = fmt.Fprintln(cmd.OutOrStdout()) _, _ = fmt.Fprintln(cmd.OutOrStdout())
return nil return nil
} }

View File

@ -67,17 +67,25 @@ func Root() *cobra.Command {
cmd.SetVersionTemplate(versionTemplate()) cmd.SetVersionTemplate(versionTemplate())
cmd.AddCommand( cmd.AddCommand(
autostart(),
autostop(),
configSSH(), configSSH(),
server(), create(),
delete(),
gitssh(),
list(),
login(), login(),
parameters(), parameters(),
templates(),
users(),
workspaces(),
ssh(),
workspaceTunnel(),
gitssh(),
publickey(), publickey(),
server(),
show(),
start(),
stop(),
ssh(),
templates(),
update(),
users(),
tunnel(),
workspaceAgent(), workspaceAgent(),
) )

View File

@ -8,7 +8,7 @@ import (
"github.com/coder/coder/codersdk" "github.com/coder/coder/codersdk"
) )
func workspaceShow() *cobra.Command { func show() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "show", Use: "show",
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),

View File

@ -10,11 +10,10 @@ import (
"github.com/coder/coder/codersdk" "github.com/coder/coder/codersdk"
) )
func workspaceStart() *cobra.Command { func start() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "start <workspace>", Use: "start <workspace>",
ValidArgsFunction: validArgsWorkspaceName, Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd) client, err := createClient(cmd)
if err != nil { if err != nil {

View File

@ -10,11 +10,10 @@ import (
"github.com/coder/coder/codersdk" "github.com/coder/coder/codersdk"
) )
func workspaceStop() *cobra.Command { func stop() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "stop <workspace>", Use: "stop <workspace>",
ValidArgsFunction: validArgsWorkspaceName, Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
client, err := createClient(cmd) client, err := createClient(cmd)
if err != nil { if err != nil {

View File

@ -115,7 +115,7 @@ func templateCreate() *cobra.Command {
"The "+cliui.Styles.Keyword.Render(templateName)+" template has been created! "+ "The "+cliui.Styles.Keyword.Render(templateName)+" template has been created! "+
"Developers can provision a workspace with this template using:")+"\n") "Developers can provision a workspace with this template using:")+"\n")
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render(fmt.Sprintf("coder workspaces create --template=%q [workspace name]", templateName))) _, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render(fmt.Sprintf("coder create --template=%q [workspace name]", templateName)))
_, _ = fmt.Fprintln(cmd.OutOrStdout()) _, _ = fmt.Fprintln(cmd.OutOrStdout())
return nil return nil

View File

@ -2,7 +2,7 @@ package cli
import "github.com/spf13/cobra" import "github.com/spf13/cobra"
func workspaceTunnel() *cobra.Command { func tunnel() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "tunnel", Use: "tunnel",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {

View File

@ -9,7 +9,7 @@ import (
"github.com/coder/coder/codersdk" "github.com/coder/coder/codersdk"
) )
func workspaceUpdate() *cobra.Command { func update() *cobra.Command {
return &cobra.Command{ return &cobra.Command{
Use: "update", Use: "update",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {

View File

@ -79,7 +79,7 @@ Run `+cliui.Styles.Code.Render("coder login "+client.URL.String())+` to authenti
Your email is: `+cliui.Styles.Field.Render(email)+` Your email is: `+cliui.Styles.Field.Render(email)+`
Your password is: `+cliui.Styles.Field.Render(password)+` Your password is: `+cliui.Styles.Field.Render(password)+`
Create a workspace `+cliui.Styles.Code.Render("coder workspaces create")+`!`) Create a workspace `+cliui.Styles.Code.Render("coder create")+`!`)
return nil return nil
}, },
} }

View File

@ -1,51 +0,0 @@
package cli
import (
"strings"
"github.com/spf13/cobra"
"github.com/coder/coder/codersdk"
)
func workspaces() *cobra.Command {
cmd := &cobra.Command{
Use: "workspaces",
Aliases: []string{"ws"},
}
cmd.AddCommand(workspaceCreate())
cmd.AddCommand(workspaceDelete())
cmd.AddCommand(workspaceList())
cmd.AddCommand(workspaceShow())
cmd.AddCommand(workspaceStop())
cmd.AddCommand(workspaceStart())
cmd.AddCommand(ssh())
cmd.AddCommand(workspaceUpdate())
cmd.AddCommand(workspaceAutostart())
cmd.AddCommand(workspaceAutostop())
return cmd
}
func validArgsWorkspaceName(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
client, err := createClient(cmd)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
organization, err := currentOrganization(cmd, client)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
workspaces, err := client.WorkspacesByOwner(cmd.Context(), organization.ID, codersdk.Me)
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
names := make([]string, 0)
for _, workspace := range workspaces {
if !strings.HasPrefix(workspace.Name, toComplete) {
continue
}
names = append(names, workspace.Name)
}
return names, cobra.ShellCompDirectiveDefault
}

View File

@ -59,7 +59,7 @@ coder templates create
Create a workspace and connect to it via SSH: Create a workspace and connect to it via SSH:
```bash ```bash
coder workspaces create my-first-workspace coder create my-first-workspace
coder ssh my-first-workspace coder ssh my-first-workspace
``` ```

View File

@ -10,10 +10,10 @@ templates](./templates.md):
```sh ```sh
# create a workspace from the template; specify any variables # create a workspace from the template; specify any variables
coder workspaces create <workspace-name> coder create <workspace-name>
# show the resources behind the workspace, and how to connect # show the resources behind the workspace, and how to connect
coder workspaces show <workspace-name> coder show <workspace-name>
``` ```
## Connect with SSH ## Connect with SSH
@ -72,5 +72,5 @@ Use the following command to update a workspace to the latest template version.
The workspace will be stopped and started: The workspace will be stopped and started:
```sh ```sh
coder workspaces update <workspace-name> coder update <workspace-name>
``` ```