Path: blob/main/components/supervisor/cmd/terminal-new.go
2498 views
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package cmd56import (7"context"8"fmt"9"time"1011"github.com/spf13/cobra"1213"github.com/gitpod-io/gitpod/common-go/log"14"github.com/gitpod-io/gitpod/supervisor/api"15)1617var terminalNewOpts struct {18Detach bool19}2021var terminalNewCmd = &cobra.Command{22Use: "new",23Short: "opens a new terminal",24Run: func(cmd *cobra.Command, args []string) {25client := api.NewTerminalServiceClient(dialSupervisor())2627ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)28defer cancel()29resp, err := client.Open(ctx, &api.OpenTerminalRequest{})30if err != nil {31log.WithError(err).Fatal("cannot open new terminal")32}3334if terminalNewOpts.Detach {35fmt.Println(resp.Terminal.Alias)36return37}3839attachToTerminal(context.Background(), client, resp.Terminal.Alias, attachToTerminalOpts{40Interactive: true,41Token: resp.StarterToken,42})43},44}4546func init() {47terminalCmd.AddCommand(terminalNewCmd)4849terminalNewCmd.Flags().BoolVarP(&terminalNewOpts.Detach, "detach", "d", false, "don't attach to the new terminal")50}515253