gitpod/components/gitpod-cli/cmd/timeout-show.go
Filip Troníček 880f186042 gp timeout set and gp timeout show to echo back the server-interpreted display duration
This means that 1439m doesn't become "1439 minutes", but rather "29 hours and 59 minutes"
2023-02-10 11:38:15 +01:00

49 lines
1.1 KiB
Go

// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package cmd
import (
"context"
"fmt"
"time"
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
"github.com/spf13/cobra"
)
// showTimeoutCommand shows the workspace timeout
var showTimeoutCommand = &cobra.Command{
Use: "show",
Short: "Show the current workspace timeout",
RunE: func(cmd *cobra.Command, args []string) error {
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
defer cancel()
wsInfo, err := gitpod.GetWSInfo(ctx)
if err != nil {
return err
}
client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{
"function:getWorkspaceTimeout",
"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",
})
if err != nil {
return err
}
defer client.Close()
res, err := client.GetWorkspaceTimeout(ctx, wsInfo.WorkspaceId)
if err != nil {
return err
}
fmt.Printf("Workspace timeout is set to %s.\n", res.HumanReadableDuration)
return nil
},
}
func init() {
timeoutCmd.AddCommand(showTimeoutCommand)
}