@@ -12,7 +12,6 @@ import (
1212 "github.com/facebookgo/stackerr"
1313 "github.com/mitchellh/go-homedir"
1414 "github.com/skratchdot/open-golang/open"
15- "github.com/spf13/cobra"
1615)
1716
1817type credentials struct {
@@ -21,7 +20,7 @@ type credentials struct {
2120 token string
2221}
2322
24- type loginCmd struct {
23+ type login struct {
2524 credentials credentials
2625 tokenReader io.Reader
2726}
@@ -35,7 +34,7 @@ to reset your password`)
3534 parseNetrc = filepath .Join (".parse" , "netrc" )
3635)
3736
38- func (l * loginCmd ) populateCreds (e * env ) error {
37+ func (l * login ) populateCreds (e * env ) error {
3938 if l .credentials .email != "" && l .credentials .password != "" {
4039 return nil
4140 }
@@ -63,7 +62,7 @@ func (l *loginCmd) populateCreds(e *env) error {
6362 return nil
6463}
6564
66- func (l * loginCmd ) getTokensReader () (io.Reader , error ) {
65+ func (l * login ) getTokensReader () (io.Reader , error ) {
6766 if l .tokenReader != nil {
6867 return l .tokenReader , nil
6968 }
@@ -80,7 +79,7 @@ func (l *loginCmd) getTokensReader() (io.Reader, error) {
8079 return file , nil
8180}
8281
83- func (l * loginCmd ) getTokenCredentials (e * env ) (* credentials , error ) {
82+ func (l * login ) getTokenCredentials (e * env ) (* credentials , error ) {
8483 reader , err := l .getTokensReader ()
8584 if err != nil {
8685 return nil , stackerr .Wrap (err )
@@ -103,7 +102,7 @@ func (l *loginCmd) getTokenCredentials(e *env) (*credentials, error) {
103102 }, nil
104103}
105104
106- func (l * loginCmd ) updatedNetrcContent (
105+ func (l * login ) updatedNetrcContent (
107106 e * env ,
108107 content io.Reader ,
109108 credentials * credentials ,
@@ -132,7 +131,7 @@ func (l *loginCmd) updatedNetrcContent(
132131 return updatedContent , nil
133132}
134133
135- func (l * loginCmd ) storeCredentials (e * env , credentials * credentials ) error {
134+ func (l * login ) storeCredentials (e * env , credentials * credentials ) error {
136135 if l .tokenReader != nil {
137136 // tests should not store credentials
138137 return nil
@@ -158,14 +157,14 @@ func (l *loginCmd) storeCredentials(e *env, credentials *credentials) error {
158157 return stackerr .Wrap (err )
159158}
160159
161- func (l * loginCmd ) authUserWithToken (e * env ) error {
160+ func (l * login ) authUserWithToken (e * env ) error {
162161 tokenCredentials , err := l .getTokenCredentials (e )
163162
164163 if err != nil {
165164 return err
166165 }
167166
168- apps := & apps {login : loginCmd {credentials : * tokenCredentials }}
167+ apps := & apps {login : login {credentials : * tokenCredentials }}
169168 _ , err = apps .restFetchApps (e )
170169 if err == errAuth {
171170 fmt .Fprintf (e .Err ,
@@ -184,7 +183,7 @@ please type "parse login" and provide a valid token for the email.
184183 return nil
185184}
186185
187- func (l * loginCmd ) authUser (e * env ) error {
186+ func (l * login ) authUser (e * env ) error {
188187 if l .authUserWithToken (e ) == nil {
189188 return nil
190189 }
@@ -215,7 +214,7 @@ func (l *loginCmd) authUser(e *env) error {
215214 return errAuth
216215}
217216
218- func (l * loginCmd ) helpCreateToken (e * env ) {
217+ func (l * login ) helpCreateToken (e * env ) {
219218 var shouldOpen string
220219 fmt .Fscanf (e .In , "%s\n " , & shouldOpen )
221220 if shouldOpen == "n" {
@@ -235,7 +234,7 @@ Please open %q in the browser to create a new account key.
235234
236235const keysURL = "https://www.parse.com/account/keys"
237236
238- func (l * loginCmd ) run (e * env ) error {
237+ func (l * login ) run (e * env ) error {
239238 fmt .Fprintf (e .Out ,
240239 `Please enter the email id you used to register with Parse
241240and an account key if you already generated it.
@@ -250,7 +249,7 @@ please type: "y" to open the browser or "n" to continue: `,
250249 fmt .Fprintf (e .Out , "Account Key: " )
251250 fmt .Fscanf (e .In , "%s\n " , & credentials .token )
252251
253- _ , err := (& apps {login : loginCmd {credentials : credentials }}).restFetchApps (e )
252+ _ , err := (& apps {login : login {credentials : credentials }}).restFetchApps (e )
254253 if err != nil {
255254 if err == errAuth {
256255 fmt .Fprintf (e .Err , `Sorry, we do not have a user with this email and account key.
@@ -270,13 +269,3 @@ Please follow instructions at %s to generate a new account key.
270269 }
271270 return stackerr .Wrap (err )
272271}
273-
274- func newLoginCmd (e * env ) * cobra.Command {
275- l := & loginCmd {}
276- return & cobra.Command {
277- Use : "login" ,
278- Short : "Login with your Parse credentials" ,
279- Long : `Login with your parse user name and an account key.` ,
280- Run : runNoArgs (e , l .run ),
281- }
282- }
0 commit comments