archive

package
v0.0.0-...-c6bd661 Latest Latest
Warning

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

Go to latest
Published: May 20, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &Z.Cmd{
	Name:    "archive",
	Summary: "archives a users list",
	Commands: []*Z.Cmd{
		help.Cmd,
	},
	Comp:    complist.New(),
	Usage:   "<list name>",
	NumArgs: 1,
	Call: func(_ *Z.Cmd, args ...string) error {
		files, err := list.List()
		if err != nil {
			return err
		}

		if _, ok := files[args[0]]; !ok {
			return fmt.Errorf("list %q does not exist", args[0])
		}

		archive := false
		prompt := &survey.Confirm{
			Message: fmt.Sprintf("Are you sure you want to archive %s?", args[0]),
		}
		survey.AskOne(prompt, &archive)

		if !archive {
			return nil
		}

		directory := filepath.Dir(files[args[0]])
		base := filepath.Base(files[args[0]])

		archiveDir := filepath.Join(directory, "archive")
		if _, err := os.Stat(archiveDir); os.IsNotExist(err) {
			err := os.Mkdir(archiveDir, 0755)
			if err != nil {
				return err
			}
		}

		newPath := filepath.Join(archiveDir, base)
		err = os.Rename(files[args[0]], newPath)
		if err != nil {
			return err
		}

		return nil
	},
}

rootCmd is the main command for the list command line tool its just holds all the other useful commands

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