bookmark

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: 14 Imported by: 0

Documentation

Index

Constants

View Source
const IdRegexString = `^[a-zA-Z]+(?:-*[0-9a-zA-Z]+)*$`

Variables

View Source
var ClearCmd = &cobra.Command{
	Use:     "clear",
	Aliases: []string{"cl", "c"},
	Args:    cobra.NoArgs,
	Short:   "Delete all bookmark entries",
	Long: `Delete all bookmark entries.

This is an alias for 'forget --all'.

Note that the bookmarks are shared between all terminal sessions.`,
	Run: func(cmd *cobra.Command, args []string) {
		all = true
		ForgetCmd.Run(cmd, args)
		cmd.Println("Bookmarks cleared.")
	},
}
View Source
var ForgetCmd = &cobra.Command{
	Use:     "forget [<name> ...]",
	Aliases: []string{"f"},
	Args:    cobra.ArbitraryArgs,
	Short:   "Delete a bookmark entry",
	Long: `Delete a bookmark entry.
	
Either one or more bookmark keys or the '--all' flag must be specified.
If bookmark keys are specified, the corresponding bookmark entries will be deleted.
Missing entries are ignored.

If the '--all' flag is set, all bookmark entries will be deleted.

Note that the bookmarks are shared between all terminal sessions.`,
	Run: func(cmd *cobra.Command, args []string) {
		if (len(args) > 0) == all {
			libutils.Fatal(1, "either one or more bookmark keys or the '--all' flag must be specified")
		}

		sRoot := storage.GetStorageRootPath()
		var names []string
		if all {
			sDirs, err := vfs.ReadDir(fs.FS, sRoot)
			if err != nil && !vfs.IsNotExist(err) {
				libutils.Fatal(1, "error reading bookmark directory: %w\n", err)
			}
			names = make([]string, 0, len(sDirs))
			for _, sDir := range sDirs {
				if !sDir.IsDir() {
					continue
				}
				names = append(names, sDir.Name())
			}
		} else {
			names = args
		}
		for _, name := range names {
			debug.Debug("Deleting bookmark entry '%s'", name)
			if err := fs.FS.RemoveAll(filepath.Join(sRoot, name)); err != nil {
				libutils.Fatal(1, "error deleting bookmark entry '%s': %w\n", name, err)
			}
			cmd.Printf("Bookmark entry '%s' deleted.\n", name)
		}
	},
}
View Source
var LoadCmd = &cobra.Command{
	Use:     "load [<key>]",
	Aliases: []string{"l"},
	Args:    cobra.RangeArgs(0, 1),
	Short:   "Load the bookmarked configuration",
	Long: `Load the configuration that is bookmarked under the given key.

Simply speaking, the 'save' subcommand stores the current kubeconfig and this one can then be used to load it again.
Bookmarking the kubeconfig does not change it in any way, loading overwrites the current kubeconfig with the stored one.

The key must consist of alphanumerical characters and dashes only, and it must neither begin nor end with a dash.
If no key is given, you will be prompted for one.

Note that loading kubeconfigs might not work if they have been created by plugins which have side effects when creating the kubeconfig,
as only the kubeconfig and the plugin's state are restored, but the side effects cannot be reproduced.

Loading a key that does not exist will result in an error and not change the current configuration.

Note that the bookmarks are shared between all terminal sessions.`,
	Run: func(cmd *cobra.Command, args []string) {
		var arg string
		if len(args) > 0 {
			arg = args[0]
		}
		key := bookmarkIndexFromArgumentOrPrompt(arg, nil)
		validateStoreLoadKey(key)
		if err := storage.ManualLoad(key); err != nil {
			libutils.Fatal(1, "error loading bookmark: %w\n", err)
		}
	},
}
View Source
var SaveCmd = &cobra.Command{
	Use:     "save [<key>]",
	Aliases: []string{"store", "s"},
	Args:    cobra.RangeArgs(0, 1),
	Short:   "Bookmark the current configuration",
	Long: `Bookmark the current configuration under the given key.

Simply speaking, this command bookmarks the current kubeconfig and the 'load' subcommand can then be used to load it again.
Bookmarking the kubeconfig does not change it in any way, loading overwrites the current kubeconfig with the stored one.
Subsequent calls with the same key will overwrite the previously stored configuration with the current one.

The key must consist of alphanumerical characters and dashes only, and it must neither begin nor end with a dash.
If no key is given, you will be prompted for one.

Note that loading kubeconfigs might not work if they have been created by plugins which have side effects when creating the kubeconfig,
as only the kubeconfig and the plugin's state are restored, but the side effects cannot be reproduced.

Note that the bookmarks are shared between all terminal sessions.`,
	Run: func(cmd *cobra.Command, args []string) {
		var key string
		if len(args) > 0 {
			key = args[0]
		} else {
			key = promptForBookmarkKey(cmd)
		}
		validateStoreLoadKey(key)
		if err := storage.ManualStore(key); err != nil {
			libutils.Fatal(1, "error storing configuration: %w\n", err)
		}
	},
}
View Source
var ViewCmd = &cobra.Command{
	Use:     "view",
	Aliases: []string{"list", "ls", "v"},
	Args:    cobra.NoArgs,
	Short:   "View the bookmarks",
	Long:    `View the bookmarks.`,
	Run: func(cmd *cobra.Command, args []string) {
		si, err := storage.RenderStorageInventory()
		if err != nil {
			libutils.Fatal(1, "error creating internal bookmark representation: %w\n", err)
		}

		var data []byte
		switch output {
		case libutils.OUTPUT_TEXT:
			data = []byte(si.String())
		case libutils.OUTPUT_JSON:
			data, err = json.MarshalIndent(si, "", "  ")
			if err != nil {
				libutils.Fatal(1, "error converting bookmark inventory to json: %w\n", err)
			}
		case libutils.OUTPUT_YAML:
			data, err = yaml.Marshal(si)
			if err != nil {
				libutils.Fatal(1, "error converting bookmark inventory to yaml: %w\n", err)
			}
		}
		sData := string(data)
		if strings.HasSuffix(sData, "\n") {
			cmd.Print(sData)
		} else {
			cmd.Println(sData)
		}
	},
}

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