Path: blob/main/components/gitpod-cli/cmd/timeout-show.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"context"8"fmt"9"time"1011"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"12"github.com/spf13/cobra"13)1415// showTimeoutCommand shows the workspace timeout16var showTimeoutCommand = &cobra.Command{17Use: "show",18Short: "Show the current workspace timeout",19RunE: func(cmd *cobra.Command, args []string) error {20ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)21defer cancel()22wsInfo, err := gitpod.GetWSInfo(ctx)23if err != nil {24return err25}26client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{27"function:getWorkspaceTimeout",28"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",29})30if err != nil {31return err32}33defer client.Close()3435res, err := client.GetWorkspaceTimeout(ctx, wsInfo.WorkspaceId)36if err != nil {37return err38}39duration, err := time.ParseDuration(res.Duration)40if err != nil {41return err42}4344fmt.Printf("Workspace timeout is set to %s.\n", getHumanReadableDuration(res.HumanReadableDuration, duration))45return nil46},47}4849func init() {50timeoutCmd.AddCommand(showTimeoutCommand)51}525354