Path: blob/main/components/local-app/cmd/config-context-use.go
2497 views
// Copyright (c) 2023 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"fmt"89"github.com/gitpod-io/local-app/pkg/config"10"github.com/spf13/cobra"11)1213var configContextUseCmd = &cobra.Command{14Use: "use <name>",15Short: "Sets the active context",16Args: cobra.ExactArgs(1),17RunE: func(cmd *cobra.Command, args []string) error {18cmd.SilenceUsage = true1920targetContext := args[0]21cfg := config.FromContext(cmd.Context())22if _, ok := cfg.Contexts[targetContext]; !ok {23return fmt.Errorf("unknown context: %s", targetContext)24}25cfg.ActiveContext = targetContext26err := config.SaveConfig(cfg.Filename, cfg)27if err != nil {28return err29}30return nil31},32}3334func init() {35configContextCmd.AddCommand(configContextUseCmd)36}373839