pass

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CopyCmd = &cobra.Command{
	Use:   "copy",
	Short: "Copies the stored password to system clipboard",
	Long: `The show command retrieves and copies the stored password for a given account,
Usage examples:

cred pass show <filepath>`,
	Run: func(cmd *cobra.Command, args []string) {
		core.CopyLogic("pass", args)
	},
}

CopyCmd represents the {cred pass copy <filepath>} command

View Source
var CpCmd = &cobra.Command{
	Use:   "cp",
	Short: "copies files and directories",
	Long: `The cp command allows you to copies files and directories.
It uses the 'cp' command to move the specified file or directory to a new location.

Examples:
  cred pass cp <source> <destination>`,
	Run: func(cmd *cobra.Command, args []string) {
		core.CpLogic("pass", args)
	},
}

CpCmd represents the {cred pass cp <src> <dest>} command

View Source
var EditCmd = &cobra.Command{
	Use:   "edit",
	Short: "Edit a password entry",
	Long: `Edit a password entry in the password store.

This command allows you to edit an existing password entry in your password store.
Usage:
  cred pass edit <filepath>`,
	Run: func(cmd *cobra.Command, args []string) {
		core.EditLogic("pass", args)
	},
}

EditCmd represents the {cred pass edit <filepath>} command

View Source
var GenerateCmd = &cobra.Command{
	Use:   "generate",
	Short: "Generate a new password and store it securely",
	Long: `The generate command creates a new password of specified length and stores it securely in the password store.
You can specify the length of the password using the -l flag. If the file already exists, you will be prompted to overwrite it.

Examples:
  pass generate mypassword -l 16
  pass generate anotherpassword -l 24`,
	Run: func(cmd *cobra.Command, args []string) {
		usage := "pass generate <filepath> [flags: -l {length}]"

		passStore := config.Constants.PassPath
		if len(args) < 1 {
			fmt.Println("invalid usage, expected: ", usage)
			return
		}
		filePath := args[0] + ".gpg"
		fullPath := paths.BuildPath(passStore, filePath)

		length, _ := cmd.Flags().GetInt("length")
		allowLower, _ := cmd.Flags().GetBool("allow-lower")
		allowUpper, _ := cmd.Flags().GetBool("allow-upper")
		allowDigit, _ := cmd.Flags().GetBool("allow-digit")
		allowSpecial, _ := cmd.Flags().GetBool("allow-special")
		generatedPassword := utils.GenerateRandom(
			length,
			allowLower,
			allowUpper,
			allowDigit,
			allowSpecial,
		)

		if paths.CheckPathExists(fullPath) {
			var choice string
			fmt.Print("The file already exists. Do you want to overwrite it? (y/n): ")
			fmt.Scanln(&choice)

			if strings.ToLower(choice) != "y" {
				return
			}

			if err := os.RemoveAll(fullPath); err != nil {
				fmt.Println("failed to remove the file: ", err)
			}
		}

		if err := gpgcrypt.AddFile(fullPath, generatedPassword, true); err != nil {
			fmt.Println("failed to insert password: ", err)
			return
		}
		fmt.Println("password inserted successfully and copied to clipboard")
	},
}

GenerateCmd represents the {cred pass generate <filepath> [-l (length)]} command

View Source
var InsertCmd = &cobra.Command{
	Use:   "insert",
	Short: "Insert a new password entry",
	Long: `The insert command allows you to add a new password entry to the password store.
You will be prompted to enter and confirm the password, which will be stored securely.
If the entry already exists, you will be asked whether you want to overwrite it.

Examples:
  pass insert <filepath>`,
	Run: func(cmd *cobra.Command, args []string) {
		usage := "pass insert <filename>"

		passStore := config.Constants.PassPath
		if len(args) < 1 {
			fmt.Println("invalid usage, expected: ", usage)
			return
		}
		path := args[0] + ".gpg"
		fullPath := paths.BuildPath(passStore, path)

		if paths.CheckPathExists(fullPath) {
			var choice string
			fmt.Print("The file already exists. Do you want to overwrite it? (y/n): ")
			fmt.Scanln(&choice)

			if choice != "y" && choice != "Y" {
				return
			}
		}

		fmt.Print("Enter password (input will be hidden): ")
		bytePassword, err := term.ReadPassword(int(syscall.Stdin))
		if err != nil {
			fmt.Println("failed to read password: ", err)
		}
		fmt.Println()

		fmt.Print("enter confirm password (input will be hidden): ")
		byteConfirmPassword, err := term.ReadPassword(int(syscall.Stdin))
		if err != nil {
			fmt.Println("failed to read confirm password: ", err)
		}
		fmt.Println()

		password, confirmPassword := string(bytePassword), string(byteConfirmPassword)

		if password == "" || (password != confirmPassword) {
			fmt.Println("passwords do not match or invalid input")
			return
		}

		if paths.CheckPathExists(fullPath) {
			if err := os.RemoveAll(fullPath); err != nil {
				fmt.Println("failed to remove the file: ", err)
				return
			}
		}

		if err := gpgcrypt.AddFile(fullPath, password, true); err != nil {
			fmt.Println("failed to insert password: ", err)
			return
		}
		fmt.Println("password inserted successfully")
	},
}

InsertCmd represents the {cred pass insert <filepath>} command

View Source
var LsCmd = &cobra.Command{
	Use:   "ls",
	Short: "List files and directories",
	Long: `The ls command allows you to list files and directories.
It uses the 'ls' command to display the contents of the current directory.

Examples:
  cred pass ls <path>`,
	Run: func(cmd *cobra.Command, args []string) {
		core.LsLogic("pass", args)
	},
}

LsCmd represents the {cred pass ls <path>} command

View Source
var MkdirCmd = &cobra.Command{
	Use:   "mkdir",
	Short: "Create directories",
	Long: `The mkdir command allows you to create directories, including nested directories.
It uses the 'mkdir' command to create the specified path.

Examples:
  cred pass mkdir <path>`,
	Run: func(cmd *cobra.Command, args []string) {
		core.MkdirLogic("pass", args)
	},
}

RmCmd represents the {cred pass rm <path>} command

View Source
var MvCmd = &cobra.Command{
	Use:   "mv",
	Short: "Move files and directories",
	Long: `The mv command allows you to move files and directories.
It uses the 'mv' command to move the specified file or directory to a new location.

Examples:
  cred pass mv <source> <destination>`,
	Run: func(cmd *cobra.Command, args []string) {
		core.MvLogic("pass", args)
	},
}

MvCmd represents the {cred pass mv <src> <dest>} command

View Source
var RmCmd = &cobra.Command{
	Use:   "rm",
	Short: "Remove files and directories",
	Long: `The rm command allows you to remove files and directories recursively.
It uses the 'rm' command to delete the specified path.

Examples:
  cred pass rm <path>`,
	Run: func(cmd *cobra.Command, args []string) {
		core.RmLogic("pass", args)
	},
}

RmCmd represents the {cred pass rm <path>} command

View Source
var ShowCmd = &cobra.Command{
	Use:   "show",
	Short: "Displays the stored password",
	Long: `The show command retrieves and displays the stored password for a given account.
Usage examples:

cred pass show <account_path>`,
	Run: func(cmd *cobra.Command, args []string) {
		core.ShowLogic("pass", args)
	},
}

ShowCmd represents the {cred pass show <account_path>} command

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
JackTT - Gopher 🇻🇳