Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/local-app/cmd/workspace-list-classes.go
2497 views
1
// Copyright (c) 2023 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
"context"
9
"time"
10
11
"github.com/bufbuild/connect-go"
12
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
13
"github.com/gitpod-io/local-app/pkg/prettyprint"
14
"github.com/spf13/cobra"
15
)
16
17
// workspaceListClassesCmd lists available workspace classes
18
var workspaceListClassesCmd = &cobra.Command{
19
Use: "list-classes",
20
Short: "Lists workspace classes",
21
RunE: func(cmd *cobra.Command, args []string) error {
22
cmd.SilenceUsage = true
23
24
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
25
defer cancel()
26
27
gitpod, err := getGitpodClient(ctx)
28
if err != nil {
29
return err
30
}
31
32
classes, err := gitpod.Workspaces.ListWorkspaceClasses(ctx, connect.NewRequest(&v1.ListWorkspaceClassesRequest{}))
33
if err != nil {
34
return err
35
}
36
37
res := make([]tabularWorkspaceClass, 0, len(classes.Msg.GetResult()))
38
for _, class := range classes.Msg.GetResult() {
39
res = append(res, tabularWorkspaceClass{
40
ID: class.Id,
41
Name: class.DisplayName,
42
Description: class.Description,
43
})
44
}
45
46
return WriteTabular(res, workspaceListClassesOpts.Format, prettyprint.WriterFormatWide)
47
},
48
}
49
50
type tabularWorkspaceClass struct {
51
ID string `print:"id"`
52
Name string `print:"name"`
53
Description string `print:"description"`
54
}
55
56
var workspaceListClassesOpts struct {
57
Format formatOpts
58
}
59
60
func init() {
61
workspaceCmd.AddCommand(workspaceListClassesCmd)
62
addFormatFlags(workspaceListClassesCmd, &workspaceListClassesOpts.Format)
63
}
64
65