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-editors.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
type workspaceListEditorsOptions struct {
18
Latest bool
19
}
20
21
// workspaceListEditors lists available editor options
22
var workspaceListEditors = &cobra.Command{
23
Use: "list-editors",
24
Short: "Lists workspace editor options",
25
RunE: func(cmd *cobra.Command, args []string) error {
26
cmd.SilenceUsage = true
27
28
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
29
defer cancel()
30
31
gitpod, err := getGitpodClient(ctx)
32
if err != nil {
33
return err
34
}
35
36
editors, err := gitpod.Editors.ListEditorOptions(ctx, connect.NewRequest(&v1.ListEditorOptionsRequest{}))
37
if err != nil {
38
return err
39
}
40
41
res := make([]tabularWorkspaceEditor, 0, len(editors.Msg.GetResult()))
42
for _, editor := range editors.Msg.GetResult() {
43
res = append(res, tabularWorkspaceEditor{
44
ID: editor.Id,
45
Name: editor.Title,
46
Flavor: editor.Label,
47
Version: editor.Stable.Version,
48
})
49
}
50
51
return WriteTabular(res, workspaceListEditorsOpts.Format, prettyprint.WriterFormatWide)
52
},
53
}
54
55
type tabularWorkspaceEditor struct {
56
ID string `print:"id"`
57
Name string `print:"name"`
58
Flavor string `print:"flavor"`
59
Version string `print:"version"`
60
}
61
62
var workspaceListEditorsOpts struct {
63
Format formatOpts
64
}
65
66
var workspaceListEditorOpts workspaceListEditorsOptions
67
68
func init() {
69
workspaceCmd.AddCommand(workspaceListEditors)
70
71
workspaceListEditors.Flags().BoolVar(&workspaceListEditorOpts.Latest, "latest", false, "show latest versions instead of stable")
72
addFormatFlags(workspaceListEditors, &workspaceListEditorsOpts.Format)
73
}
74
75