Path: blob/main/components/local-app/cmd/config-context-delete.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"log/slog"89"github.com/gitpod-io/local-app/pkg/auth"10"github.com/gitpod-io/local-app/pkg/config"11"github.com/spf13/cobra"12)1314var configContextDeleteCmd = &cobra.Command{15Use: "delete <name>",16Short: "Deletes a context",17Args: cobra.ExactArgs(1),18RunE: func(cmd *cobra.Command, args []string) (err error) {19cmd.SilenceUsage = true2021targetContext := args[0]22cfg := config.FromContext(cmd.Context())2324var update bool25defer func() {26if err == nil && update {27slog.Debug("saving config", "filename", cfg.Filename)28err = config.SaveConfig(cfg.Filename, cfg)29}30}()3132if cfg.ActiveContext == targetContext {33slog.Info("deleting active context - use `gitpod config use-context` to set a new active context")34cfg.ActiveContext = ""35update = true36}3738gpctx := cfg.Contexts[targetContext]39if gpctx == nil {40return nil41}42delete(cfg.Contexts, targetContext)43update = true4445err = auth.DeleteToken(gpctx.Host.String())46if err != nil {47slog.Warn("did not delete token from keyring", "err", err)48err = nil49}5051return nil52},53}5455func init() {56configContextCmd.AddCommand(configContextDeleteCmd)57}585960