Path: blob/main/components/gitpod-cli/cmd/stop-workspace.go
2498 views
// Copyright (c) 2020 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"time"910"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"11"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"12"github.com/spf13/cobra"13)1415// stopWorkspaceCmd represents the stopWorkspaceCmd command16var stopWorkspaceCmd = &cobra.Command{17Use: "stop",18Short: "Stop current workspace",19Args: cobra.ArbitraryArgs,20RunE: func(cmd *cobra.Command, args []string) error {21// TOOD: currently, we skip sending analysis because we cannot send it while the workspace stopping.22utils.TrackCommandUsageEvent.Command = nil2324ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)25defer cancel()26wsInfo, err := gitpod.GetWSInfo(ctx)27if err != nil {28return err29}30client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{31"function:stopWorkspace",32"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",33})34if err != nil {35return err36}37defer client.Close()38return client.StopWorkspace(ctx, wsInfo.WorkspaceId)39},40}4142func init() {43rootCmd.AddCommand(stopWorkspaceCmd)44}454647