Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/cmd/timeout-show.go
2498 views
1
// Copyright (c) 2022 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
"fmt"
10
"time"
11
12
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
13
"github.com/spf13/cobra"
14
)
15
16
// showTimeoutCommand shows the workspace timeout
17
var showTimeoutCommand = &cobra.Command{
18
Use: "show",
19
Short: "Show the current workspace timeout",
20
RunE: func(cmd *cobra.Command, args []string) error {
21
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
22
defer cancel()
23
wsInfo, err := gitpod.GetWSInfo(ctx)
24
if err != nil {
25
return err
26
}
27
client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{
28
"function:getWorkspaceTimeout",
29
"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",
30
})
31
if err != nil {
32
return err
33
}
34
defer client.Close()
35
36
res, err := client.GetWorkspaceTimeout(ctx, wsInfo.WorkspaceId)
37
if err != nil {
38
return err
39
}
40
duration, err := time.ParseDuration(res.Duration)
41
if err != nil {
42
return err
43
}
44
45
fmt.Printf("Workspace timeout is set to %s.\n", getHumanReadableDuration(res.HumanReadableDuration, duration))
46
return nil
47
},
48
}
49
50
func init() {
51
timeoutCmd.AddCommand(showTimeoutCommand)
52
}
53
54