Path: blob/main/components/supervisor/cmd/terminal-list.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"os"10"sort"11"strings"12"text/tabwriter"13"time"1415"github.com/spf13/cobra"1617"github.com/gitpod-io/gitpod/common-go/log"18"github.com/gitpod-io/gitpod/supervisor/api"19)2021var terminalListCmd = &cobra.Command{22Use: "list",23Short: "lists all of supervisor's terminals",24Run: func(cmd *cobra.Command, args []string) {25client := api.NewTerminalServiceClient(dialSupervisor())2627ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)28defer cancel()2930resp, err := client.List(ctx, &api.ListTerminalsRequest{})31if err != nil {32log.WithError(err).Fatal("cannot list terminals")33}3435tw := tabwriter.NewWriter(os.Stdout, 2, 4, 1, ' ', 0)36defer tw.Flush()3738fmt.Fprintf(tw, "ALIAS\tPID\tCOMMAND\tANNOTATIONS\n")39for _, term := range resp.Terminals {40annotations := make([]string, 0, len(term.Annotations))41for k, v := range term.Annotations {42annotations = append(annotations, fmt.Sprintf("%s=%s", k, v))43}44sort.Slice(annotations, func(i, j int) bool { return annotations[i] < annotations[j] })45fmt.Fprintf(tw, "%s\t%d\t%s\t%s\n", term.Alias, term.Pid, strings.Join(term.Command, " "), strings.Join(annotations, ","))46}47},48}4950func init() {51terminalCmd.AddCommand(terminalListCmd)52}535455