Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/supervisor/cmd/terminal-new.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
"fmt"
10
"time"
11
12
"github.com/spf13/cobra"
13
14
"github.com/gitpod-io/gitpod/common-go/log"
15
"github.com/gitpod-io/gitpod/supervisor/api"
16
)
17
18
var terminalNewOpts struct {
19
Detach bool
20
}
21
22
var terminalNewCmd = &cobra.Command{
23
Use: "new",
24
Short: "opens a new terminal",
25
Run: func(cmd *cobra.Command, args []string) {
26
client := api.NewTerminalServiceClient(dialSupervisor())
27
28
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
29
defer cancel()
30
resp, err := client.Open(ctx, &api.OpenTerminalRequest{})
31
if err != nil {
32
log.WithError(err).Fatal("cannot open new terminal")
33
}
34
35
if terminalNewOpts.Detach {
36
fmt.Println(resp.Terminal.Alias)
37
return
38
}
39
40
attachToTerminal(context.Background(), client, resp.Terminal.Alias, attachToTerminalOpts{
41
Interactive: true,
42
Token: resp.StarterToken,
43
})
44
},
45
}
46
47
func init() {
48
terminalCmd.AddCommand(terminalNewCmd)
49
50
terminalNewCmd.Flags().BoolVarP(&terminalNewOpts.Detach, "detach", "d", false, "don't attach to the new terminal")
51
}
52
53