Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/local-app/cmd/workspace-get.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
"log/slog"
10
"time"
11
12
"github.com/bufbuild/connect-go"
13
v1 "github.com/gitpod-io/gitpod/components/public-api/go/experimental/v1"
14
"github.com/gitpod-io/local-app/pkg/prettyprint"
15
"github.com/spf13/cobra"
16
)
17
18
var workspaceGetOpts struct {
19
Format formatOpts
20
}
21
22
var workspaceGetCmd = &cobra.Command{
23
Use: "get <workspace-id>",
24
Short: "Retrieves metadata about a given workspace",
25
Args: cobra.MinimumNArgs(1),
26
RunE: func(cmd *cobra.Command, args []string) error {
27
var workspaces []tabularWorkspace
28
for _, workspaceID := range args {
29
ctx, cancel := context.WithTimeout(cmd.Context(), 30*time.Second)
30
defer cancel()
31
32
gitpod, err := getGitpodClient(ctx)
33
if err != nil {
34
return err
35
}
36
37
slog.Debug("Attempting to retrieve workspace info...", "workspaceID", workspaceID)
38
ws, err := gitpod.Workspaces.GetWorkspace(ctx, connect.NewRequest(&v1.GetWorkspaceRequest{WorkspaceId: workspaceID}))
39
if err != nil {
40
return err
41
}
42
43
r := newTabularWorkspace(ws.Msg.GetResult())
44
if r == nil {
45
continue
46
}
47
workspaces = append(workspaces, *r)
48
}
49
return WriteTabular(workspaces, workspaceGetOpts.Format, prettyprint.WriterFormatNarrow)
50
},
51
}
52
53
func init() {
54
workspaceCmd.AddCommand(workspaceGetCmd)
55
addFormatFlags(workspaceGetCmd, &workspaceGetOpts.Format)
56
}
57
58