func (c *configureCmd) accountKey(e *parsecli.Env) error { token, err := c.login.HelpCreateToken(e) if err != nil { return err } email, err := c.login.AuthToken(e, token) if err != nil { fmt.Fprintln(e.Err, "Could not store credentials. Please try again.\n") return err } if c.isDefault { email = "" } var l parsecli.Login if c.tokenReader != nil { l.TokenReader = c.tokenReader } foundEmail, creds, err := l.GetTokenCredentials(e, email) firstEverConfigure := false if stackerr.HasUnderlying(err, stackerr.MatcherFunc(os.IsNotExist)) && !c.isDefault { firstEverConfigure = true } if creds != nil { if c.isDefault { fmt.Fprintln( e.Err, "Note: this operation will overwrite the default account key", ) } else if foundEmail { fmt.Fprintf( e.Err, `Note: this operation will overwrite the account key: %q for email: %q `, parsecli.Last4(token), email, ) } } err = c.login.StoreCredentials(e, email, &parsecli.Credentials{Token: token}) if err == nil { if c.isDefault { fmt.Fprintln(e.Out, "Successfully stored default account key.") } else { fmt.Fprintf(e.Out, "Successfully stored account key for: %q.\n", email) } } if err != nil { fmt.Fprintln(e.Err, "Could not save account key.") return stackerr.Wrap(err) } if firstEverConfigure { fmt.Fprintln( e.Out, ` Looks like this is the first time you have configured an account key. Note that "parse new" and "parse list" can automatically pick up a default key if present. Otherwise, you'll have to explicitly set the PARSER_EMAIL common.Environment variable for them to pick the correct account key. Further, if the command line tool cannot find an account key for a configured email it will try to use the default account key. Hence, we are automatically configuring the default account key to be the same as current account key. `, ) err = c.login.StoreCredentials(e, "", &parsecli.Credentials{Token: token}) if err != nil { fmt.Fprintln(e.Err, "Could not save account key.") return stackerr.Wrap(err) } fmt.Fprintln(e.Out, `Successfully configured the default account key. To change the default account key in future use: "parse configure accountkey -d" `) } return nil }