gitpod/components/local-app/cmd/config-context-list.go
Christian Weichel 3b831546ea
Restructure config and contexts (#19086)
* Restructure config and contexts

* Org ID and Host in `config get`

* Bump version

---------

Co-authored-by: Filip Troníček <filip@gitpod.io>
2023-11-21 18:51:59 +02:00

50 lines
1.2 KiB
Go

// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package cmd
import (
"github.com/gitpod-io/local-app/pkg/config"
"github.com/gitpod-io/local-app/pkg/prettyprint"
"github.com/spf13/cobra"
)
var configContextsListCmd = &cobra.Command{
Use: "list",
Short: "Lists the available contexts",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
cfg := config.FromContext(cmd.Context())
res := make([]tabularContext, 0, len(cfg.Contexts))
for name, ctx := range cfg.Contexts {
res = append(res, tabularContext{
Active: name == cfg.ActiveContext,
Name: name,
Host: ctx.Host.String(),
Organization: ctx.OrganizationID,
})
}
return WriteTabular(res, configContextsListpts.Format, prettyprint.WriterFormatWide)
},
}
type tabularContext struct {
Active bool
Name string
Host string
Organization string
}
var configContextsListpts struct {
Format formatOpts
}
func init() {
configContextCmd.AddCommand(configContextsListCmd)
addFormatFlags(configContextsListCmd, &configContextsListpts.Format)
}