Path: blob/main/components/local-app/cmd/workspace-get.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"log/slog"9"time"1011"github.com/bufbuild/connect-go"12v1 "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)1617var workspaceGetOpts struct {18Format formatOpts19}2021var workspaceGetCmd = &cobra.Command{22Use: "get <workspace-id>",23Short: "Retrieves metadata about a given workspace",24Args: cobra.MinimumNArgs(1),25RunE: func(cmd *cobra.Command, args []string) error {26var workspaces []tabularWorkspace27for _, workspaceID := range args {28ctx, cancel := context.WithTimeout(cmd.Context(), 30*time.Second)29defer cancel()3031gitpod, err := getGitpodClient(ctx)32if err != nil {33return err34}3536slog.Debug("Attempting to retrieve workspace info...", "workspaceID", workspaceID)37ws, err := gitpod.Workspaces.GetWorkspace(ctx, connect.NewRequest(&v1.GetWorkspaceRequest{WorkspaceId: workspaceID}))38if err != nil {39return err40}4142r := newTabularWorkspace(ws.Msg.GetResult())43if r == nil {44continue45}46workspaces = append(workspaces, *r)47}48return WriteTabular(workspaces, workspaceGetOpts.Format, prettyprint.WriterFormatNarrow)49},50}5152func init() {53workspaceCmd.AddCommand(workspaceGetCmd)54addFormatFlags(workspaceGetCmd, &workspaceGetOpts.Format)55}565758