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-use.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
"fmt"
9
10
"github.com/gitpod-io/local-app/pkg/config"
11
"github.com/spf13/cobra"
12
)
13
14
var configContextUseCmd = &cobra.Command{
15
Use: "use <name>",
16
Short: "Sets the active context",
17
Args: cobra.ExactArgs(1),
18
RunE: func(cmd *cobra.Command, args []string) error {
19
cmd.SilenceUsage = true
20
21
targetContext := args[0]
22
cfg := config.FromContext(cmd.Context())
23
if _, ok := cfg.Contexts[targetContext]; !ok {
24
return fmt.Errorf("unknown context: %s", targetContext)
25
}
26
cfg.ActiveContext = targetContext
27
err := config.SaveConfig(cfg.Filename, cfg)
28
if err != nil {
29
return err
30
}
31
return nil
32
},
33
}
34
35
func init() {
36
configContextCmd.AddCommand(configContextUseCmd)
37
}
38
39