gitpod/components/local-app/cmd/workspace-list-classes.go
Christian Weichel 5b6c63d278
Add (out-out) telemetry to CLI (#19033)
* Rename AddApology to MarkExceptional

* Add telemetry

* Improve login failure behaviour

* Fix list format

* Generate identity based on the MAC
2023-11-08 17:25:46 +02:00

64 lines
1.7 KiB
Go

// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package cmd
import (
"context"
"time"
"github.com/bufbuild/connect-go"
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
"github.com/gitpod-io/local-app/pkg/prettyprint"
"github.com/spf13/cobra"
)
// workspaceListClassesCmd lists available workspace classes
var workspaceListClassesCmd = &cobra.Command{
Use: "list-classes",
Short: "Lists workspace classes",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
defer cancel()
gitpod, err := getGitpodClient(ctx)
if err != nil {
return err
}
classes, err := gitpod.Workspaces.ListWorkspaceClasses(ctx, connect.NewRequest(&v1.ListWorkspaceClassesRequest{}))
if err != nil {
return err
}
res := make([]tabularWorkspaceClass, 0, len(classes.Msg.GetResult()))
for _, class := range classes.Msg.GetResult() {
res = append(res, tabularWorkspaceClass{
ID: class.Id,
Name: class.DisplayName,
Description: class.Description,
})
}
return WriteTabular(res, workspaceListClassesOpts.Format, prettyprint.WriterFormatWide)
},
}
type tabularWorkspaceClass struct {
ID string `print:"id"`
Name string `print:"name"`
Description string `print:"description"`
}
var workspaceListClassesOpts struct {
Format formatOpts
}
func init() {
workspaceCmd.AddCommand(workspaceListClassesCmd)
addFormatFlags(workspaceListClassesCmd, &workspaceListClassesOpts.Format)
}