basic

package
v1.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const CustomCmdPluginName = "<internal_custom>"
View Source
const TemporaryCmdPluginName = "<internal_temporary>"

Variables

View Source
var CustomCmd = &cobra.Command{
	Use:     "custom <path>",
	Aliases: []string{"cus", "c"},
	Args:    cobra.ExactArgs(1),
	GroupID: cmdgroups.Basic,
	Short:   "Switch to the kubeconfig at the specified path",
	Long: `Switch to the kubeconfig at the specified path.

This creates a symlink from $KUBECONFIG pointing to the given file.`,
	Run: func(cmd *cobra.Command, args []string) {
		con := config.Runtime.Context()
		con.SetPluginName(CustomCmdPluginName)

		path := args[0]
		path, err := filepath.Abs(path)
		if err != nil {
			libutils.Fatal(1, "error getting absolute path: %w\n", err)
		}
		if err := con.WriteKubeconfigSymlink(path, "Switched to custom kubeconfig from '%s'.", path); err != nil {
			libutils.Fatal(1, "error creating kubeconfig symlink: %w\n", err)
		}

		pathForId := path
		customCfg := config.Runtime.Config().Builtin.GetBuiltinCustomConfig()
		if customCfg != nil && customCfg.MaxIdLength > 0 && len(pathForId) > customCfg.MaxIdLength {
			pathForId = fmt.Sprintf("…%s", path[len(path)-customCfg.MaxIdLength:])
		}
		if err := con.WriteId("custom:%s", pathForId); err != nil {
			libutils.Fatal(1, "error writing id: %w\n", err)
		}
		if err := con.WritePluginState(&customPluginState{Source: path}); err != nil {
			libutils.Fatal(1, "error writing plugin state: %w\n", err)
		}
	},
}

CustomCmd represents the custom command

View Source
var TemporaryCmd = &cobra.Command{
	Use:     "temporary",
	Aliases: []string{"temp", "tmp", "t"},
	Args:    cobra.NoArgs,
	GroupID: cmdgroups.Basic,
	Short:   "Switch to the kubeconfig currently contained in the clipboard",
	Long:    `Switch to the kubeconfig currently contained in the clipboard.`,
	Run: func(cmd *cobra.Command, args []string) {
		con := config.Runtime.Context()
		con.SetPluginName(TemporaryCmdPluginName)

		kcfg_string, err := clipboard.ReadAll()
		if err != nil {
			libutils.Fatal(1, "error reading from clipboard: %w\n", err)
		}
		kcfg_data := []byte(kcfg_string)
		if err := con.WriteKubeconfig(kcfg_data, "Switched to kubeconfig from clipboard."); err != nil {
			libutils.Fatal(1, "error writing kubeconfig: %w\n", err)
		}
		kcfg, err := libutils.ParseKubeconfig(kcfg_data)
		if err != nil {
			libutils.Fatal(1, "error parsing kubeconfig: %w\n", err)
		}
		host, err := libutils.GetCurrentApiserverHost(kcfg)
		if err != nil {
			libutils.Fatal(1, "error getting current apiserver host from kubeconfig: %w\n", err)
		}
		if err := con.WriteId("temp:%s", host); err != nil {
			libutils.Fatal(1, "error writing id: %w\n", err)
		}
	},
}

TemporaryCmd represents the temporary command

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL