mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
* Improve CLI documentation * feat: Allow workspace resources to attach multiple agents This enables a "kubernetes_pod" to attach multiple agents that could be for multiple services. Each agent is required to have a unique name, so SSH syntax is: `coder ssh <workspace>.<agent>` A resource can have zero agents too, they aren't required. * Add tree view * Improve table UI * feat: Allow workspace resources to attach multiple agents This enables a "kubernetes_pod" to attach multiple agents that could be for multiple services. Each agent is required to have a unique name, so SSH syntax is: `coder ssh <workspace>.<agent>` A resource can have zero agents too, they aren't required. * Rename `tunnel` to `skip-tunnel` This command was `true` by default, which causes a confusing user experience. * Add disclaimer about editing templates * Add help to template create * Improve workspace create flow * Add end-to-end test for config-ssh * Improve testing of config-ssh * Fix workspace list * Fix config ssh tests * Update cli/configssh.go Co-authored-by: Cian Johnston <public@cianjohnston.ie> * Fix requested changes * Remove socat requirement * Fix resources not reading in TTY Co-authored-by: Cian Johnston <public@cianjohnston.ie>
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/jedib0t/go-pretty/v6/table"
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/coder/coder/cli/cliui"
|
|
"github.com/coder/coder/coderd/database"
|
|
"github.com/coder/coder/codersdk"
|
|
)
|
|
|
|
func workspaceList() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "list",
|
|
Aliases: []string{"ls"},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client, err := createClient(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
workspaces, err := client.WorkspacesByUser(cmd.Context(), codersdk.Me)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(workspaces) == 0 {
|
|
_, _ = fmt.Fprintln(cmd.OutOrStdout(), cliui.Styles.Prompt.String()+"No workspaces found! Create one:")
|
|
_, _ = fmt.Fprintln(cmd.OutOrStdout())
|
|
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+cliui.Styles.Code.Render("coder workspaces create <name>"))
|
|
_, _ = fmt.Fprintln(cmd.OutOrStdout())
|
|
return nil
|
|
}
|
|
|
|
tableWriter := table.NewWriter()
|
|
tableWriter.SetStyle(table.StyleLight)
|
|
tableWriter.Style().Options.SeparateColumns = false
|
|
tableWriter.AppendHeader(table.Row{"Workspace", "Template", "Status", "Last Built", "Outdated"})
|
|
|
|
for _, workspace := range workspaces {
|
|
status := ""
|
|
inProgress := false
|
|
if workspace.LatestBuild.Job.Status == codersdk.ProvisionerJobRunning ||
|
|
workspace.LatestBuild.Job.Status == codersdk.ProvisionerJobCanceling {
|
|
inProgress = true
|
|
}
|
|
|
|
switch workspace.LatestBuild.Transition {
|
|
case database.WorkspaceTransitionStart:
|
|
status = "start"
|
|
if inProgress {
|
|
status = "starting"
|
|
}
|
|
case database.WorkspaceTransitionStop:
|
|
status = "stop"
|
|
if inProgress {
|
|
status = "stopping"
|
|
}
|
|
case database.WorkspaceTransitionDelete:
|
|
status = "delete"
|
|
if inProgress {
|
|
status = "deleting"
|
|
}
|
|
}
|
|
|
|
tableWriter.AppendRow(table.Row{
|
|
cliui.Styles.Bold.Render(workspace.Name),
|
|
workspace.TemplateName,
|
|
status,
|
|
workspace.LatestBuild.Job.CreatedAt.Format("January 2, 2006"),
|
|
workspace.Outdated,
|
|
})
|
|
}
|
|
_, err = fmt.Fprintf(cmd.OutOrStdout(), tableWriter.Render())
|
|
return err
|
|
},
|
|
}
|
|
}
|