mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
48 lines
926 B
Go
48 lines
926 B
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 (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var wait bool
|
|
|
|
var openCmd = &cobra.Command{
|
|
Use: "open",
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
file, err := filepath.Abs(args[0])
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
url := getCliApiUrl()
|
|
query := url.Query()
|
|
query.Add("op", "open")
|
|
query.Add("file", file)
|
|
query.Add("wait", fmt.Sprintf("%t", wait))
|
|
url.RawQuery = query.Encode()
|
|
|
|
resp, err := http.Get(url.String())
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if resp.StatusCode != http.StatusOK {
|
|
log.Fatal(resp.Status)
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(openCmd)
|
|
openCmd.Flags().BoolVar(&wait, "wait", false, "")
|
|
}
|