cmd

package
v0.0.0-...-a60e539 Latest Latest
Warning

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

Go to latest
Published: May 20, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use: "",
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		if cmd.Name() == "help" {
			return
		}

		if len(archiveFile) == 0 {
			exitWithErr(errNoArchiveFile)
		}
		archiveFile = fixArchivePath(archiveFile)

		if cmd.Name() == "create" {
			if archiveExists(archiveFile) {
				exitWithErr(errArchiveExists)
			}
		} else {
			if !archiveExists(archiveFile) {
				exitWithErr(errArchiveDoesNotExist)
			}
		}

		if chunkSize < minChunkSize {
			exitWithErr(errInvalidChunkSize)
		}

		envPwd := os.Getenv("PASSWORD")
		password := []byte(envPwd)
		if len(password) == 0 {
			password = readPassword("Password")

			if cmd.Name() == "create" {
				pwdRepeat := readPassword("Repeat password")
				if !bytes.Equal(password, pwdRepeat) {
					exitWithErr(errPWDoNotMatch)
				}
			}
		}

		config := config.Config{
			Path:        archiveFile,
			Password:    password,
			Compression: useCompression,
			ChunkSize:   chunkSize,
		}

		var err error
		arch, err = archive.NewArchive(&config)
		if err != nil {
			exitWithErr(err)
		}
	},
	PersistentPostRun: func(cmd *cobra.Command, args []string) {
		if arch != nil {
			arch.Close()
		}
	},
}

RootCmd is the main command that is always executed.

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