Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ide/jetbrains/cli/cmd/open.go
2501 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
"fmt"
9
"log"
10
"net/http"
11
"path/filepath"
12
13
"github.com/spf13/cobra"
14
)
15
16
var wait bool
17
18
var openCmd = &cobra.Command{
19
Use: "open",
20
Args: cobra.ExactArgs(1),
21
Run: func(cmd *cobra.Command, args []string) {
22
file, err := filepath.Abs(args[0])
23
if err != nil {
24
log.Fatal(err)
25
}
26
27
url := getCliApiUrl()
28
query := url.Query()
29
query.Add("op", "open")
30
query.Add("file", file)
31
query.Add("wait", fmt.Sprintf("%t", wait))
32
url.RawQuery = query.Encode()
33
34
resp, err := http.Get(url.String())
35
if err != nil {
36
log.Fatal(err)
37
}
38
if resp.StatusCode != http.StatusOK {
39
log.Fatal(resp.Status)
40
}
41
},
42
}
43
44
func init() {
45
rootCmd.AddCommand(openCmd)
46
openCmd.Flags().BoolVar(&wait, "wait", false, "")
47
}
48
49