Path: blob/main/components/local-app/cmd/workspace-list-editors.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)1516type workspaceListEditorsOptions struct {17Latest bool18}1920// workspaceListEditors lists available editor options21var workspaceListEditors = &cobra.Command{22Use: "list-editors",23Short: "Lists workspace editor options",24RunE: func(cmd *cobra.Command, args []string) error {25cmd.SilenceUsage = true2627ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)28defer cancel()2930gitpod, err := getGitpodClient(ctx)31if err != nil {32return err33}3435editors, err := gitpod.Editors.ListEditorOptions(ctx, connect.NewRequest(&v1.ListEditorOptionsRequest{}))36if err != nil {37return err38}3940res := make([]tabularWorkspaceEditor, 0, len(editors.Msg.GetResult()))41for _, editor := range editors.Msg.GetResult() {42res = append(res, tabularWorkspaceEditor{43ID: editor.Id,44Name: editor.Title,45Flavor: editor.Label,46Version: editor.Stable.Version,47})48}4950return WriteTabular(res, workspaceListEditorsOpts.Format, prettyprint.WriterFormatWide)51},52}5354type tabularWorkspaceEditor struct {55ID string `print:"id"`56Name string `print:"name"`57Flavor string `print:"flavor"`58Version string `print:"version"`59}6061var workspaceListEditorsOpts struct {62Format formatOpts63}6465var workspaceListEditorOpts workspaceListEditorsOptions6667func init() {68workspaceCmd.AddCommand(workspaceListEditors)6970workspaceListEditors.Flags().BoolVar(&workspaceListEditorOpts.Latest, "latest", false, "show latest versions instead of stable")71addFormatFlags(workspaceListEditors, &workspaceListEditorsOpts.Format)72}737475