1
0
mirror of https://github.com/writeas/writeas-cli synced 2025-07-22 22:08:13 +00:00

Merge pull request #43 from writeas/T692

Add password flag for authentication

Closes T692
This commit is contained in:
Matt Baer 2020-02-27 13:25:40 -05:00 committed by GitHub
commit 62e03522f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -238,6 +238,10 @@ func main() {
Name: "verbose, v",
Usage: "Make the operation more talkative",
},
cli.StringFlag{
Name: "password, p",
Usage: "The password for the account being logged into",
},
},
},
{

View File

@ -408,15 +408,20 @@ func CmdAuth(c *cli.Context) error {
}
}
fmt.Print("Password: ")
pass, err := gopass.GetPasswdMasked()
if err != nil {
return cli.NewExitError(fmt.Sprintf("error reading password: %v", err), 1)
}
// Take password from argument, and fall back to input
pass := c.String("p")
if pass == "" {
fmt.Print("Password: ")
enteredPass, err := gopass.GetPasswdMasked()
if err != nil {
return cli.NewExitError(fmt.Sprintf("error reading password: %v", err), 1)
}
// Validate password
if len(pass) == 0 {
return cli.NewExitError("Please enter your password.", 1)
// Validate password
if len(enteredPass) == 0 {
return cli.NewExitError("Please enter your password.", 1)
}
pass = string(enteredPass)
}
if config.IsTor(c) {
@ -424,7 +429,7 @@ func CmdAuth(c *cli.Context) error {
} else {
log.Info(c, "Logging in...")
}
err = api.DoLogIn(c, username, string(pass))
err = api.DoLogIn(c, username, pass)
if err != nil {
return cli.NewExitError(fmt.Sprintf("error logging in: %v", err), 1)
}