func Add(args ...string) int { safe, err := loadSafe() if err != nil { return handleError(err) } name, username, password, errCode := parseAddArgs(args) if errCode > 0 { return errCode } account, err := safe.Add(name, username, password) if _, conflict := err.(*errors.AccountExists); conflict && overwrite(name) { var replaceErr error if account, replaceErr = safe.Replace(name, username, password); replaceErr != nil { return handleError(replaceErr) } } else if err != nil { return handleError(err) } fmt.Println("Credential added") if utils.Confirm("Copy password to clipboard", true) { if err := utils.CopyToClipboard(account.Password); err != nil { return handleError(err) } } return 0 }
func Copy(args ...string) int { safe, err := loadSafe() if err != nil { return handleError(err) } account, err := safe.Get(args[0]) if err != nil { return handleError(err) } if err := utils.CopyToClipboard(account.Password); err != nil { return handleError(err) } return 0 }