Skip to content
This repository was archived by the owner on Jan 16, 2021. It is now read-only.

Commit 3ba44cd

Browse files
committed
rename loginCmd to login across the entire code
1 parent 50324c8 commit 3ba44cd

File tree

4 files changed

+21
-32
lines changed

4 files changed

+21
-32
lines changed

apps.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type app struct {
3434
}
3535

3636
type apps struct {
37-
login loginCmd
37+
login login
3838
}
3939

4040
const numRetries = 3
@@ -91,7 +91,7 @@ func getAuthHeaders(credentials *credentials, headers http.Header) http.Header {
9191
}
9292

9393
func fetchAppKeys(e *env, appID string) (*app, error) {
94-
l := &loginCmd{}
94+
l := &login{}
9595
err := l.authUser(e)
9696
if err != nil {
9797
return nil, err

apps_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
var (
1919
defaultCredentials = credentials{email: "email", password: "password"}
2020
defaultTokenCredentials = credentials{email: "email", token: "token"}
21-
defaultApps = apps{login: loginCmd{credentials: defaultCredentials}}
22-
defaultAppsWithToken = apps{login: loginCmd{credentials: defaultTokenCredentials}}
21+
defaultApps = apps{login: login{credentials: defaultCredentials}}
22+
defaultAppsWithToken = apps{login: login{credentials: defaultTokenCredentials}}
2323
)
2424

2525
func newTestApp(suffix string) *app {

login_cmd.go renamed to login.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1817
type 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

236235
const 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
241240
and 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-
}

login_cmd_test.go renamed to login_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestPopulateCreds(t *testing.T) {
1515
h := newHarness(t)
1616
defer h.Stop()
1717

18-
l := &loginCmd{}
18+
l := &login{}
1919
h.env.In = strings.NewReader("email\npassword\n")
2020
ensure.Nil(t, l.populateCreds(h.env))
2121
ensure.DeepEqual(t, l.credentials.email, "email")
@@ -28,7 +28,7 @@ func TestGetTokenCredentials(t *testing.T) {
2828
h := newHarness(t)
2929
defer h.Stop()
3030

31-
l := &loginCmd{}
31+
l := &login{}
3232
h.env.Server = "http://api.example.com/1/"
3333

3434
l.tokenReader = strings.NewReader(
@@ -53,7 +53,7 @@ func TestAuthUserWithToken(t *testing.T) {
5353
h, _ := newAppHarness(t)
5454
defer h.Stop()
5555

56-
l := &loginCmd{}
56+
l := &login{}
5757
h.env.Server = "http://api.example.org/1/"
5858

5959
l.tokenReader = strings.NewReader(
@@ -71,7 +71,7 @@ func TestUpdatedNetrcContent(t *testing.T) {
7171
h := newHarness(t)
7272
defer h.Stop()
7373

74-
l := &loginCmd{}
74+
l := &login{}
7575

7676
h.env.Server = "https://api.example.com/1/"
7777
updated, err := l.updatedNetrcContent(h.env,
@@ -131,7 +131,7 @@ func TestLogin(t *testing.T) {
131131
h, _ := newAppHarness(t)
132132
defer h.Stop()
133133

134-
l := &loginCmd{tokenReader: strings.NewReader("")}
134+
l := &login{tokenReader: strings.NewReader("")}
135135

136136
h.env.In = ioutil.NopCloser(strings.NewReader("n\nemail\ntoken\n"))
137137
ensure.Nil(t, l.run(h.env))

0 commit comments

Comments
 (0)