diff --git a/cmd/writeas/main.go b/cmd/writeas/main.go index e9c1019..40bff74 100644 --- a/cmd/writeas/main.go +++ b/cmd/writeas/main.go @@ -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", + }, }, }, { diff --git a/commands/commands.go b/commands/commands.go index 29ddc21..d6a55d6 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -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) }