Path: blob/main/dev/gpctl/cmd/public-api-workspaces-list.go
2498 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"github.com/gitpod-io/gitpod/common-go/log"8v1 "github.com/gitpod-io/gitpod/components/public-api/go/v1"9"github.com/spf13/cobra"10)1112var publicApiWorkspacesListCmd = &cobra.Command{13Use: "list",14Aliases: []string{"ls"},15Short: "List your workspaces",16Args: cobra.ExactArgs(1),17Run: func(cmd *cobra.Command, args []string) {18organizationID := args[0]1920conn, err := newPublicAPIConn()21if err != nil {22log.Log.WithError(err).Fatal()23}2425service := v1.NewWorkspaceServiceClient(conn)2627resp, err := service.ListWorkspaces(cmd.Context(), &v1.ListWorkspacesRequest{OrganizationId: organizationID})28if err != nil {29log.WithError(err).Fatal("failed to retrieve workspace list")30return31}3233tpl := `ID OrganizationID ContextURL InstanceID InstanceStatus34{{- range .Workspaces }}35{{ .Id }} {{ .OrganizationId }} {{ .ContextUrl }} {{ .Status.InstanceId }} {{ .Status.Phase.Name }}36{{ end }}37`38err = getOutputFormat(tpl, "{..id}").Print(resp)39if err != nil {40log.Fatal(err)41}42},43}4445func init() {46publicApiWorkspacesCmd.AddCommand(publicApiWorkspacesListCmd)47}484950