Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/gpctl/cmd/public-api-workspaces-list.go
2498 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"github.com/gitpod-io/gitpod/common-go/log"
9
v1 "github.com/gitpod-io/gitpod/components/public-api/go/v1"
10
"github.com/spf13/cobra"
11
)
12
13
var publicApiWorkspacesListCmd = &cobra.Command{
14
Use: "list",
15
Aliases: []string{"ls"},
16
Short: "List your workspaces",
17
Args: cobra.ExactArgs(1),
18
Run: func(cmd *cobra.Command, args []string) {
19
organizationID := args[0]
20
21
conn, err := newPublicAPIConn()
22
if err != nil {
23
log.Log.WithError(err).Fatal()
24
}
25
26
service := v1.NewWorkspaceServiceClient(conn)
27
28
resp, err := service.ListWorkspaces(cmd.Context(), &v1.ListWorkspacesRequest{OrganizationId: organizationID})
29
if err != nil {
30
log.WithError(err).Fatal("failed to retrieve workspace list")
31
return
32
}
33
34
tpl := `ID OrganizationID ContextURL InstanceID InstanceStatus
35
{{- range .Workspaces }}
36
{{ .Id }} {{ .OrganizationId }} {{ .ContextUrl }} {{ .Status.InstanceId }} {{ .Status.Phase.Name }}
37
{{ end }}
38
`
39
err = getOutputFormat(tpl, "{..id}").Print(resp)
40
if err != nil {
41
log.Fatal(err)
42
}
43
},
44
}
45
46
func init() {
47
publicApiWorkspacesCmd.AddCommand(publicApiWorkspacesListCmd)
48
}
49
50