cmd

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2022 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GitVersion = "unknown"
	GitCommit  = "unknown"
	BuildDate  = "unknown"
)
View Source
var ErrFileLocked = errors.New("file is locked")
View Source
var RootCmd = &cobra.Command{
	Use:     "pasuman",
	Short:   "A command-line password manager",
	Version: "1.0.0",
	PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
		cmd.SilenceUsage = true

		createDataFile := cmd == addCmd || cmd == masterPasswordCmd
		config.Init(rootCmdProfile, createDataFile)

		if cmd == removeLockCmd ||
			cmd.Name() == cobra.ShellCompRequestCmd || cmd.Name() == cobra.ShellCompNoDescRequestCmd {
			return nil
		}

		lockFile := config.PasumanDataFile + ".lock"

		_, err := os.Stat(lockFile)

		if errors.Is(err, os.ErrNotExist) {
			if _, err := os.Create(lockFile); err != nil {
				return err
			}
		} else {
			return fmt.Errorf("%w: use `pasuman remove-lock` command to remove it "+
				"(only if no other pasuman process is running!)", ErrFileLocked)
		}

		return nil
	},

	PersistentPostRunE: func(cmd *cobra.Command, _ []string) error {
		if cmd.Name() == "__complete" {
			return nil
		}

		return RemoveLock()
	},
}

Functions

func RemoveLock

func RemoveLock() error

RemoveLock - removes the lock created by the `PersistentPreRunE` of the root command. We want to execute this even if the command fails (in the `RunE` part). If there is an error during RunE, PersistentPostRunE is not run. So as far as I know, we should also call `RemoveLock` manually in the `main.go`.

func Version

func Version() string

Types

This section is empty.

Jump to

Keyboard shortcuts

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