Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/ssh-load-test/cmd/root.go
2498 views
1
package cmd
2
3
import (
4
"net/url"
5
"strings"
6
7
"github.com/helloyi/go-sshclient"
8
"github.com/spf13/cobra"
9
)
10
11
var wsUrlStr string
12
var ownerToken string
13
14
var rootCmd = &cobra.Command{
15
Use: "newCLI",
16
Short: "A brief description of your application",
17
Long: "",
18
}
19
20
func Execute() {
21
cobra.CheckErr(rootCmd.Execute())
22
}
23
24
func init() {
25
rootCmd.PersistentFlags().StringVarP(&wsUrlStr, "url", "u", "", "Url of workspace")
26
rootCmd.PersistentFlags().StringVarP(&ownerToken, "token", "t", "", "Owner token of workspace")
27
}
28
29
func connSSH() (*sshclient.Client, error) {
30
wsUrl, err := url.Parse(wsUrlStr)
31
if err != nil {
32
panic(err)
33
}
34
host := wsUrl.Host
35
wsID := strings.Split(wsUrl.Host, ".")[0]
36
cli, err := sshclient.DialWithPasswd(host+":22", wsID, ownerToken)
37
return cli, err
38
}
39
40