Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-cli/cmd/stop-workspace.go
2498 views
1
// Copyright (c) 2020 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
"time"
10
11
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod"
12
"github.com/gitpod-io/gitpod/gitpod-cli/pkg/utils"
13
"github.com/spf13/cobra"
14
)
15
16
// stopWorkspaceCmd represents the stopWorkspaceCmd command
17
var stopWorkspaceCmd = &cobra.Command{
18
Use: "stop",
19
Short: "Stop current workspace",
20
Args: cobra.ArbitraryArgs,
21
RunE: func(cmd *cobra.Command, args []string) error {
22
// TOOD: currently, we skip sending analysis because we cannot send it while the workspace stopping.
23
utils.TrackCommandUsageEvent.Command = nil
24
25
ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second)
26
defer cancel()
27
wsInfo, err := gitpod.GetWSInfo(ctx)
28
if err != nil {
29
return err
30
}
31
client, err := gitpod.ConnectToServer(ctx, wsInfo, []string{
32
"function:stopWorkspace",
33
"resource:workspace::" + wsInfo.WorkspaceId + "::get/update",
34
})
35
if err != nil {
36
return err
37
}
38
defer client.Close()
39
return client.StopWorkspace(ctx, wsInfo.WorkspaceId)
40
},
41
}
42
43
func init() {
44
rootCmd.AddCommand(stopWorkspaceCmd)
45
}
46
47