cmd

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DecryptCmd = &cobra.Command{
	Use:   "decrypt [file|directory]...",
	Short: "Decrypt the one or more files, creating a \"decrypted version\" that can be edited.",
	Long:  "Decrypt the one or more files, creating a \"decrypted version\" that can be edited. Each arg can refer to either a file, in which case the file will be decrypted, or a directory, in which case all files under the directory will be decrypted. File args can refer to encrypted, decrypted, or plain files, existant or non-existant, as long as the correponding encrypted file exists. Supplying no args will decrypt all encrypted files in the repo.",
	Args: func(cmd *cobra.Command, args []string) error {
		if DecryptFlags.Stdout && len(args) != 1 {
			return errors.New("requires exactly 1 arg when --stdout is set")
		}
		return nil
	},
	DisableFlagsInUseLine: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		config, err := config.LoadConfig(".")
		if err != nil {
			return err
		}
		cache, err := cache.Setup(config)
		if err != nil {
			return err
		}
		defer cache.Close()
		if len(args) == 0 {
			args = []string{config.Root}
		}
		files := make([]*actions.File, 0, len(args))
		for _, arg := range args {
			var paths []string
			if info, err := os.Stat(arg); !os.IsNotExist(err) && info.IsDir() {

				paths, err = config.AllEncryptedFiles(arg)
				if err != nil {
					return err
				}
			} else {

				paths = []string{arg}
			}
			for _, path := range paths {
				var file actions.File
				if DecryptFlags.Stdout {
					file = actions.File{EncryptedPath: path}
				} else {
					file, err = actions.NewFile(path, &config)
					if err != nil {
						return err
					}
				}
				files = append(files, &file)
			}
		}
		return actions.Decrypt(files, DecryptFlags.Plain, DecryptFlags.Stdout, &cache, &config.Provider, int(threads), progress)
	},
}
View Source
var DecryptFlags struct {
	Stdout bool
	Plain  bool
}
View Source
var EncryptCmd = &cobra.Command{
	Use:                   "encrypt [file|directory]...",
	Short:                 "Encrypt one or more decrypted files in the repo, replacing the contents of the encrypted files.",
	Long:                  "Encrypt one or more decrypted files in the repo, replacing the contents of the corresponding encrypted files. Each arg can refer to either a file, in which case the file will be encrypted, or a directory, in which case all files under the directory will be encrypted. File args can refer to encrypted, decrypted, or plain files, existant or non-existant, as long as the correponding decrypted file exists. Supplying no args will encrypt all decrypted files in the repo.",
	Args:                  cobra.ArbitraryArgs,
	DisableFlagsInUseLine: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		config, err := config.LoadConfig(".")
		if err != nil {
			return err
		}
		cache, err := cache.Setup(config)
		if err != nil {
			return err
		}
		defer cache.Close()
		if len(args) == 0 {
			args = []string{config.Root}
		}
		files := make([]*actions.File, 0, len(args))
		for _, arg := range args {
			var paths []string
			if info, err := os.Stat(arg); !os.IsNotExist(err) && info.IsDir() {

				paths, err = config.AllDecryptedFiles(arg)
				if err != nil {
					return err
				}
			} else {

				paths = []string{arg}
			}
			for _, path := range paths {
				file, err := actions.NewFile(path, &config)
				if err != nil {
					return err
				}
				files = append(files, &file)
			}
		}
		return actions.Encrypt(files, &cache, &config.Provider, int(threads), progress)
	},
}

Functions

func DecryptValue added in v1.3.0

func DecryptValue(stdin io.Reader, stdout io.Writer) error

func EncryptValue added in v1.3.0

func EncryptValue(stdin io.Reader, stdout io.Writer, multiline bool) error

func Execute

func Execute()

Types

This section is empty.

Jump to

Keyboard shortcuts

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