Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var BookmarkCmd = &cobra.Command{ Use: "bookmark", Aliases: []string{"book", "bm", "b"}, GroupID: cmdgroups.Meta, Short: "Interact with the kubeconfig bookmarks", Long: `Interact with the kubeconfig bookmarks. The bookmarks can be used to store and load kubeconfigs. See the different subcommands for more information. Note that the bookmarks are shared between all terminal sessions.`, }
View Source
var FlipCmd = &cobra.Command{ Use: "flip", Aliases: []string{"f"}, Args: cobra.NoArgs, GroupID: cmdgroups.Meta, Short: "Flip the current configuration with the previously used one", Long: `Flip the current configuration with the previously used one. This is basically an alias for 'kw history load 1'. It requires a history depth of at least 1 (meaning the history must not be deactivated).`, Run: func(cmd *cobra.Command, args []string) { history.HistoryLoadCmd.Run(cmd, []string{"1"}) }, }
View Source
var HistoryCmd = &cobra.Command{ Use: "history <command>", Aliases: []string{"hist", "h"}, GroupID: cmdgroups.Meta, Short: "Interact with the history", Long: `Interact with the history. The subcommands allow to view the history and load a specific entry again.`, }
View Source
var InfoCmd = &cobra.Command{ Use: "info", Aliases: []string{"i"}, Args: cobra.NoArgs, GroupID: cmdgroups.Meta, Short: "Shows information about the current configuration", Long: `Shows information about the current configuration. Supports json and yaml output, with the latter one being the default.`, Run: func(cmd *cobra.Command, args []string) { libutils.ValidateOutputFormat(output, libutils.OUTPUT_YAML, libutils.OUTPUT_JSON) state := config.Runtime.State() rawData := map[string]any{} data, err := vfs.ReadFile(fs.FS, config.Runtime.IdPath()) if err != nil { if !vfs.IsNotExist(err) { libutils.Fatal(1, "error reading id backup file '%s': %w\n", config.Runtime.IdPath(), err) } data = []byte("<unknown>") } rawData["id"] = string(data) rawData["genericState"] = state.GenericState if len(state.RawPluginState) > 0 { ps := map[string]any{} if err := json.Unmarshal(state.RawPluginState, &ps); err != nil { libutils.Fatal(1, "error unmarshalling plugin state: %w\n", err) } rawData["pluginState"] = ps } switch output { case libutils.OUTPUT_YAML: data, err = yaml.Marshal(rawData) if err != nil { libutils.Fatal(1, "error marshalling state to yaml: %w\n", err) } case libutils.OUTPUT_JSON: data, err = json.Marshal(rawData) if err != nil { libutils.Fatal(1, "error marshalling state to json: %w\n", err) } default: libutils.Fatal(1, "unsupported output format: %s\n", output) } cmd.Println(string(data)) }, }
View Source
var NamespaceCmd = &cobra.Command{ Use: "namespace [<namespace>]", Aliases: []string{"ns"}, Args: cobra.RangeArgs(0, 1), GroupID: cmdgroups.Meta, Short: "Change the default namespace in the current context of the kubeconfig", Long: `Change the default namespace in the current context of the kubeconfig. This is basically the same thing as running 'kubectl config set-context --current --namespace=<namespace>'. If called without any argument, the command fetches the namespaces from the currently selected cluster and prompts for a selection. Note that this command does change the kubeconfig file, but doesn't create a new kubeswitcher history entry.`, Run: func(cmd *cobra.Command, args []string) { kcfg, c, err := libutils.ParseKubeconfigFromFileWithClient(config.Runtime.KubeconfigPath()) if err != nil { if vfs.IsNotExist(err) { libutils.Fatal(1, "kubeconfig not set, run another kw command to switch to a kubeconfig first\n") } libutils.Fatal(1, "error parsing kubeconfig: %w\n", err) } curCtx, ok := kcfg.Contexts[kcfg.CurrentContext] if !ok { libutils.Fatal(1, "invalid kubeconfig: current context '%s' not found\n", kcfg.CurrentContext) } namespace := "" if len(args) == 0 { nsl := &corev1.NamespaceList{} if err := c.List(cmd.Context(), nsl); err != nil { libutils.Fatal(1, "error fetching namespaces: %w\n", err) } namespaces := make([]string, len(nsl.Items)) for i, ns := range nsl.Items { namespaces[i] = ns.Name } slices.SortFunc(namespaces, func(a, b string) int { return -strings.Compare(a, b) }) namespaces = append([]string{""}, namespaces...) _, namespace, err = selector.New[string](). WithPrompt("Select Namespace: "). WithFatalOnAbort("No namespace selected."). WithFatalOnError("error selecting namespace: %w"). From(namespaces, func(elem string) string { return elem }). Select() if err != nil { libutils.Fatal(1, err.Error()) } } else { namespace = args[0] } curCtx.Namespace = namespace kcfgData, err := libutils.MarshalKubeconfig(kcfg) if err != nil { libutils.Fatal(1, "error marshaling kubeconfig: %w\n", err) } if err := vfs.WriteFile(fs.FS, config.Runtime.KubeconfigPath(), kcfgData, vfs.ModePerm); err != nil { libutils.Fatal(1, "error writing kubeconfig: %w\n", err) } }, }
View Source
var RepeatCmd = &cobra.Command{ Use: "repeat", Aliases: []string{"r"}, Args: cobra.NoArgs, GroupID: cmdgroups.Meta, Short: "Switch to the last used configuration (cross-session)", Long: `Switch to the last used configuration (cross-session). This is basically an alias for 'kw history load 0 --global'. It requires a history depth of at least 1 (meaning the history must not be deactivated).`, Run: func(cmd *cobra.Command, args []string) { history.Global = true history.HistoryLoadCmd.Run(cmd, []string{"0"}) }, }
View Source
var StorageCmd = &cobra.Command{ Use: "storage", Aliases: []string{"store", "s"}, GroupID: cmdgroups.Meta, Short: "[DEPRECATED] Interact with the kubeconfig storage", Long: `Interact with the kubeconfig storage. The storage can be used to store and load kubeconfigs. See the different subcommands for more information. Note that the storage is shared between all terminal sessions.`, Deprecated: "use 'bookmark' instead.", Run: BookmarkCmd.Run, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.