mirror of
https://github.com/gitpod-io/gitpod.git
synced 2025-12-08 17:36:30 +00:00
* Restructure config and contexts * Org ID and Host in `config get` * Bump version --------- Co-authored-by: Filip Troníček <filip@gitpod.io>
38 lines
889 B
Go
38 lines
889 B
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 (
|
|
"fmt"
|
|
|
|
"github.com/gitpod-io/local-app/pkg/config"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var configContextUseCmd = &cobra.Command{
|
|
Use: "use <name>",
|
|
Short: "Sets the active context",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
cmd.SilenceUsage = true
|
|
|
|
targetContext := args[0]
|
|
cfg := config.FromContext(cmd.Context())
|
|
if _, ok := cfg.Contexts[targetContext]; !ok {
|
|
return fmt.Errorf("unknown context: %s", targetContext)
|
|
}
|
|
cfg.ActiveContext = targetContext
|
|
err := config.SaveConfig(cfg.Filename, cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
configContextCmd.AddCommand(configContextUseCmd)
|
|
}
|