func parseAddArgs(args []string) (name, username, password string, errCode int) { if len(args) > 3 { fmt.Println("Usage: add [name] [username] [password]") return "", "", "", 1 } switch len(args) { case 3: password = args[2] fallthrough case 2: username = args[1] fallthrough case 1: name = args[0] } errCode = 1 var err error if name == "" { if name, err = utils.GetInput("Enter a credential name"); err != nil { fmt.Println(err) return } } if username == "" { if username, err = utils.GetInput(fmt.Sprintf("Enter a username for %s", name)); err != nil { fmt.Println(err) return } } if password == "" { if utils.Confirm("Generate password", true) { password, err = utils.GeneratePassword(config.General.PasswordLen) if err != nil { fmt.Println(err) return } } else { var _password []byte if _password, err = utils.GetPasswordInput(fmt.Sprintf("Enter a password for %s", name)); err != nil { fmt.Println(err) return } password = string(_password) } } errCode = 0 return }
func loadSafe() (*safe.Safe, error) { password, err := utils.GetPasswordInput("Enter your master password") if err != nil { return nil, err } backendClient, err := newBackendClient() if err != nil { return nil, err } cryptoClient, err := newCryptoClient() if err != nil { return nil, err } return safe.Load( password, backendClient, cryptoClient, config, ) }