Path: blob/main/dev/gpctl/cmd/public-api-workspaces-get.go
2498 views
// Copyright (c) 2022 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"github.com/gitpod-io/gitpod/common-go/log"8v1 "github.com/gitpod-io/gitpod/components/public-api/go/v1"9"github.com/spf13/cobra"10)1112var publicApiWorkspacesGetCmd = &cobra.Command{13Use: "get <workspace-id>",14Short: "Retrieve details about a workspace by ID",15Args: cobra.ExactArgs(1),16Run: func(cmd *cobra.Command, args []string) {17workspaceID := args[0]1819conn, err := newPublicAPIConn()20if err != nil {21log.Log.WithError(err).Fatal()22}2324service := v1.NewWorkspaceServiceClient(conn)2526log.Log.Debugf("Retrieving workspace ID: %s", workspaceID)27resp, err := service.GetWorkspace(cmd.Context(), &v1.GetWorkspaceRequest{WorkspaceId: workspaceID})28if err != nil {29log.WithError(err).Fatalf("failed to retrieve workspace (ID: %s)", workspaceID)30return31}3233tpl := `ID: {{ .Workspace.Id }}34OrganizationID: {{ .Workspace.OrganizationId }}35ContextURL: {{ .Workspace.ContextUrl }}36InstanceID: {{ .Workspace.Status.InstanceId }}37InstanceStatus: {{ .Workspace.Status.Phase.Name }}38`39err = getOutputFormat(tpl, "{..result.workspace_id}").Print(resp)40if err != nil {41log.Fatal(err)42}43},44}4546func init() {47publicApiWorkspacesCmd.AddCommand(publicApiWorkspacesGetCmd)48}495051