Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/local-app/cmd/config-context-list.go
2497 views
1
// Copyright (c) 2023 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
"github.com/gitpod-io/local-app/pkg/config"
9
"github.com/gitpod-io/local-app/pkg/prettyprint"
10
"github.com/spf13/cobra"
11
)
12
13
var configContextsListCmd = &cobra.Command{
14
Use: "list",
15
Short: "Lists the available contexts",
16
RunE: func(cmd *cobra.Command, args []string) error {
17
cmd.SilenceUsage = true
18
19
cfg := config.FromContext(cmd.Context())
20
21
res := make([]tabularContext, 0, len(cfg.Contexts))
22
for name, ctx := range cfg.Contexts {
23
res = append(res, tabularContext{
24
Active: name == cfg.ActiveContext,
25
Name: name,
26
Host: ctx.Host.String(),
27
Organization: ctx.OrganizationID,
28
})
29
}
30
31
return WriteTabular(res, configContextsListpts.Format, prettyprint.WriterFormatWide)
32
},
33
}
34
35
type tabularContext struct {
36
Active bool
37
Name string
38
Host string
39
Organization string
40
}
41
42
var configContextsListpts struct {
43
Format formatOpts
44
}
45
46
func init() {
47
configContextCmd.AddCommand(configContextsListCmd)
48
addFormatFlags(configContextsListCmd, &configContextsListpts.Format)
49
}
50
51