Path: blob/main/components/local-app/cmd/workspace-list-classes.go
2497 views
// Copyright (c) 2023 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"context"8"time"910"github.com/bufbuild/connect-go"11v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"12"github.com/gitpod-io/local-app/pkg/prettyprint"13"github.com/spf13/cobra"14)1516// workspaceListClassesCmd lists available workspace classes17var workspaceListClassesCmd = &cobra.Command{18Use: "list-classes",19Short: "Lists workspace classes",20RunE: func(cmd *cobra.Command, args []string) error {21cmd.SilenceUsage = true2223ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)24defer cancel()2526gitpod, err := getGitpodClient(ctx)27if err != nil {28return err29}3031classes, err := gitpod.Workspaces.ListWorkspaceClasses(ctx, connect.NewRequest(&v1.ListWorkspaceClassesRequest{}))32if err != nil {33return err34}3536res := make([]tabularWorkspaceClass, 0, len(classes.Msg.GetResult()))37for _, class := range classes.Msg.GetResult() {38res = append(res, tabularWorkspaceClass{39ID: class.Id,40Name: class.DisplayName,41Description: class.Description,42})43}4445return WriteTabular(res, workspaceListClassesOpts.Format, prettyprint.WriterFormatWide)46},47}4849type tabularWorkspaceClass struct {50ID string `print:"id"`51Name string `print:"name"`52Description string `print:"description"`53}5455var workspaceListClassesOpts struct {56Format formatOpts57}5859func init() {60workspaceCmd.AddCommand(workspaceListClassesCmd)61addFormatFlags(workspaceListClassesCmd, &workspaceListClassesOpts.Format)62}636465