cmd

package
v0.0.0-...-c80151b Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CompressCmd = &cobra.Command{
	Use:   "compress",
	Short: "Compress files",
	Long:  "Compress files using Gzip compression.",
	Run: func(cmd *cobra.Command, args []string) {

		inputPaths, _ := cmd.Flags().GetStringSlice("input")
		outputPaths, _ := cmd.Flags().GetStringSlice("output")

		progress := progressbar.NewOptions(len(inputPaths),
			progressbar.OptionSetDescription("[cyan][Compressing files...][reset]"),
			progressbar.OptionSetWriter(os.Stderr),
			progressbar.OptionShowCount(),
			progressbar.OptionShowBytes(true),
			progressbar.OptionEnableColorCodes(true),
		)

		for i := 0; i < len(inputPaths); i++ {
			err := CompressFile(inputPaths[i], outputPaths[i]+".gz")
			if err != nil {
				color.Red("Error compressing: %v", err)
			} else {
				progress.Add(1)
				color.Green("\nCompression successful for %s", inputPaths[i])
			}
		}
		progress.Finish()
	},
}
View Source
var DecryptCmd = &cobra.Command{
	Use:   "decrypt",
	Short: "Decrypt files",
	Long:  "Decrypt files using AES-GCM decryption.",
	Run: func(cmd *cobra.Command, args []string) {

		inputPaths, _ := cmd.Flags().GetStringSlice("input")
		outputPaths, _ := cmd.Flags().GetStringSlice("output")

		key := internal.GetKey()

		progress := progressbar.NewOptions(len(inputPaths),
			progressbar.OptionSetDescription("[cyan][Decrypting files...][reset]"),
			progressbar.OptionSetWriter(os.Stderr),
			progressbar.OptionShowCount(),
			progressbar.OptionShowBytes(true),
			progressbar.OptionEnableColorCodes(true),
		)

		for i := 0; i < len(inputPaths); i++ {
			err := DecryptFile(inputPaths[i], outputPaths[i], key)
			if err != nil {
				color.Red("Error decrypting: %v", err)
			} else {
				progress.Add(1)
				color.Green("\nDecryption successful for %s", inputPaths)
			}
		}
		progress.Finish()
	},
}
View Source
var EncryptCmd = &cobra.Command{
	Use:   "encrypt",
	Short: "Encrypt files",
	Long:  "Encrypt files using AES-GCM encryption.",
	Run: func(cmd *cobra.Command, args []string) {
		color.Cyan("Encrypting files...")

		inputPaths, _ := cmd.Flags().GetStringSlice("input")
		outputPaths, _ := cmd.Flags().GetStringSlice("output")

		key := internal.GenerateKey()

		progress := progressbar.NewOptions(len(inputPaths),
			progressbar.OptionSetDescription("[cyan][Encrypting files...][reset]"),
			progressbar.OptionSetWriter(os.Stderr),
			progressbar.OptionShowCount(),
			progressbar.OptionShowBytes(true),
			progressbar.OptionEnableColorCodes(true),
		)

		for i := 0; i < len(inputPaths); i++ {
			err := EncryptFile(inputPaths[i], outputPaths[i], key)
			if err != nil {
				color.Red("Error encrypting: %v", err)
			} else {
				progress.Add(1)
				color.Green("\nEncryption successful for %s", inputPaths)
			}
		}
		progress.Finish()
	},
}

Functions

func CompressFile

func CompressFile(inputFilePath, outputFilePath string) error

func DecryptFile

func DecryptFile(inputPaths, outputPaths string, key []byte) error

func EncryptFile

func EncryptFile(inputPaths, outputPaths string, key []byte) error

func Execute

func Execute()

func NewRootCmd

func NewRootCmd() *cobra.Command

Types

This section is empty.

Jump to

Keyboard shortcuts

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