Skip to content

Commit c760eb1

Browse files
feat(cmd): only print version mismatch warning once (#223)
Also adds additional tests to the file.
1 parent 05892a7 commit c760eb1

26 files changed

Lines changed: 242 additions & 155 deletions

cmd/apps.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"fmt"
5-
"io"
65
"os"
76
"strings"
87
"time"
@@ -18,7 +17,7 @@ import (
1817
)
1918

2019
// AppCreate creates an app.
21-
func (d DeisCmd) AppCreate(id, buildpack, remote string, noRemote bool) error {
20+
func (d *DeisCmd) AppCreate(id, buildpack, remote string, noRemote bool) error {
2221
s, err := settings.Load(d.ConfigFile)
2322
if err != nil {
2423
return err
@@ -31,7 +30,7 @@ func (d DeisCmd) AppCreate(id, buildpack, remote string, noRemote bool) error {
3130
quit <- true
3231
<-quit
3332

34-
if checkAPICompatibility(s.Client, err, d.WErr) != nil {
33+
if d.checkAPICompatibility(s.Client, err) != nil {
3534
return err
3635
}
3736

@@ -43,7 +42,7 @@ func (d DeisCmd) AppCreate(id, buildpack, remote string, noRemote bool) error {
4342
"BUILDPACK_URL": buildpack,
4443
},
4544
}
46-
if _, err = config.Set(s.Client, app.ID, configValues); checkAPICompatibility(s.Client, err, d.WErr) != nil {
45+
if _, err = config.Set(s.Client, app.ID, configValues); d.checkAPICompatibility(s.Client, err) != nil {
4746
return err
4847
}
4948
}
@@ -69,7 +68,7 @@ func (d DeisCmd) AppCreate(id, buildpack, remote string, noRemote bool) error {
6968
}
7069

7170
// AppsList lists apps on the Deis controller.
72-
func (d DeisCmd) AppsList(results int) error {
71+
func (d *DeisCmd) AppsList(results int) error {
7372
s, err := settings.Load(d.ConfigFile)
7473

7574
if err != nil {
@@ -81,7 +80,7 @@ func (d DeisCmd) AppsList(results int) error {
8180
}
8281

8382
apps, count, err := apps.List(s.Client, results)
84-
if checkAPICompatibility(s.Client, err, d.WErr) != nil {
83+
if d.checkAPICompatibility(s.Client, err) != nil {
8584
return err
8685
}
8786

@@ -94,19 +93,19 @@ func (d DeisCmd) AppsList(results int) error {
9493
}
9594

9695
// AppInfo prints info about app.
97-
func (d DeisCmd) AppInfo(appID string) error {
96+
func (d *DeisCmd) AppInfo(appID string) error {
9897
s, appID, err := load(d.ConfigFile, appID)
9998

10099
if err != nil {
101100
return err
102101
}
103102

104103
app, err := apps.Get(s.Client, appID)
105-
if checkAPICompatibility(s.Client, err, d.WErr) != nil {
104+
if d.checkAPICompatibility(s.Client, err) != nil {
106105
return err
107106
}
108107

109-
url, err := appURL(s, appID, d.WErr)
108+
url, err := d.appURL(s, appID)
110109
if err != nil {
111110
return err
112111
}
@@ -141,14 +140,14 @@ func (d DeisCmd) AppInfo(appID string) error {
141140
}
142141

143142
// AppOpen opens an app in the default webbrowser.
144-
func (d DeisCmd) AppOpen(appID string) error {
143+
func (d *DeisCmd) AppOpen(appID string) error {
145144
s, appID, err := load(d.ConfigFile, appID)
146145

147146
if err != nil {
148147
return err
149148
}
150149

151-
u, err := appURL(s, appID, d.WErr)
150+
u, err := d.appURL(s, appID)
152151
if err != nil {
153152
return err
154153
}
@@ -165,15 +164,15 @@ func (d DeisCmd) AppOpen(appID string) error {
165164
}
166165

167166
// AppLogs returns the logs from an app.
168-
func (d DeisCmd) AppLogs(appID string, lines int) error {
167+
func (d *DeisCmd) AppLogs(appID string, lines int) error {
169168
s, appID, err := load(d.ConfigFile, appID)
170169

171170
if err != nil {
172171
return err
173172
}
174173

175174
logs, err := apps.Logs(s.Client, appID, lines)
176-
if checkAPICompatibility(s.Client, err, d.WErr) != nil {
175+
if d.checkAPICompatibility(s.Client, err) != nil {
177176
return err
178177
}
179178

@@ -185,7 +184,7 @@ func (d DeisCmd) AppLogs(appID string, lines int) error {
185184
}
186185

187186
// AppRun runs a one time command in the app.
188-
func (d DeisCmd) AppRun(appID, command string) error {
187+
func (d *DeisCmd) AppRun(appID, command string) error {
189188
s, appID, err := load(d.ConfigFile, appID)
190189

191190
if err != nil {
@@ -195,7 +194,7 @@ func (d DeisCmd) AppRun(appID, command string) error {
195194
d.Printf("Running '%s'...\n", command)
196195

197196
out, err := apps.Run(s.Client, appID, command)
198-
if checkAPICompatibility(s.Client, err, d.WErr) != nil {
197+
if d.checkAPICompatibility(s.Client, err) != nil {
199198
return err
200199
}
201200

@@ -210,7 +209,7 @@ func (d DeisCmd) AppRun(appID, command string) error {
210209
}
211210

212211
// AppDestroy destroys an app.
213-
func (d DeisCmd) AppDestroy(appID, confirm string) error {
212+
func (d *DeisCmd) AppDestroy(appID, confirm string) error {
214213
gitSession := false
215214

216215
s, err := settings.Load(d.ConfigFile)
@@ -246,7 +245,7 @@ func (d DeisCmd) AppDestroy(appID, confirm string) error {
246245
startTime := time.Now()
247246
d.Printf("Destroying %s...\n", appID)
248247

249-
if err = apps.Delete(s.Client, appID); checkAPICompatibility(s.Client, err, d.WErr) != nil {
248+
if err = apps.Delete(s.Client, appID); d.checkAPICompatibility(s.Client, err) != nil {
250249
return err
251250
}
252251

@@ -260,7 +259,7 @@ func (d DeisCmd) AppDestroy(appID, confirm string) error {
260259
}
261260

262261
// AppTransfer transfers app ownership to another user.
263-
func (d DeisCmd) AppTransfer(appID, username string) error {
262+
func (d *DeisCmd) AppTransfer(appID, username string) error {
264263
s, appID, err := load(d.ConfigFile, appID)
265264

266265
if err != nil {
@@ -270,7 +269,7 @@ func (d DeisCmd) AppTransfer(appID, username string) error {
270269
d.Printf("Transferring %s to %s... ", appID, username)
271270

272271
err = apps.Transfer(s.Client, appID, username)
273-
if checkAPICompatibility(s.Client, err, d.WErr) != nil {
272+
if d.checkAPICompatibility(s.Client, err) != nil {
274273
return err
275274
}
276275

@@ -282,9 +281,9 @@ func (d DeisCmd) AppTransfer(appID, username string) error {
282281
const noDomainAssignedMsg = "No domain assigned to %s"
283282

284283
// appURL grabs the first domain an app has and returns this.
285-
func appURL(s *settings.Settings, appID string, wErr io.Writer) (string, error) {
284+
func (d *DeisCmd) appURL(s *settings.Settings, appID string) (string, error) {
286285
domains, _, err := domains.List(s.Client, appID, 1)
287-
if checkAPICompatibility(s.Client, err, wErr) != nil {
286+
if d.checkAPICompatibility(s.Client, err) != nil {
288287
return "", err
289288
}
290289

cmd/auth.go

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"errors"
55
"fmt"
6-
"io"
76
"strings"
87
"syscall"
98

@@ -14,7 +13,7 @@ import (
1413
)
1514

1615
// Register creates a account on a Deis controller.
17-
func (d DeisCmd) Register(controller string, username string, password string, email string,
16+
func (d *DeisCmd) Register(controller string, username string, password string, email string,
1817
sslVerify bool) error {
1918

2019
c, err := deis.New(sslVerify, controller, "")
@@ -32,7 +31,7 @@ func (d DeisCmd) Register(controller string, username string, password string, e
3231
// Set user agent for temporary client.
3332
c.UserAgent = settings.UserAgent
3433

35-
if err = c.CheckConnection(); checkAPICompatibility(c, err, d.WErr) != nil {
34+
if err = c.CheckConnection(); d.checkAPICompatibility(c, err) != nil {
3635
return err
3736
}
3837

@@ -66,40 +65,39 @@ func (d DeisCmd) Register(controller string, username string, password string, e
6665

6766
c.Token = ""
6867

69-
if checkAPICompatibility(c, err, d.WErr) != nil {
68+
if d.checkAPICompatibility(c, err) != nil {
7069
d.PrintErr("Registration failed: ")
7170
return err
7271
}
7372

7473
d.Printf("Registered %s\n", username)
7574

7675
s := settings.Settings{Client: c}
77-
return doLogin(d.ConfigFile, s, username, password, d.WOut, d.WErr)
76+
return d.doLogin(s, username, password)
7877
}
7978

80-
func doLogin(cf string, s settings.Settings, username, password string,
81-
wOut io.Writer, wErr io.Writer) error {
79+
func (d *DeisCmd) doLogin(s settings.Settings, username, password string) error {
8280
token, err := auth.Login(s.Client, username, password)
83-
if checkAPICompatibility(s.Client, err, wErr) != nil {
81+
if d.checkAPICompatibility(s.Client, err) != nil {
8482
return err
8583
}
8684

8785
s.Client.Token = token
8886
s.Username = username
8987

90-
filename, err := s.Save(cf)
88+
filename, err := s.Save(d.ConfigFile)
9189

9290
if err != nil {
9391
return nil
9492
}
9593

96-
fmt.Fprintf(wOut, "Logged in as %s\n", username)
97-
fmt.Fprintf(wOut, "Configuration file written to %s\n", filename)
94+
d.Printf("Logged in as %s\n", username)
95+
d.Printf("Configuration file written to %s\n", filename)
9896
return nil
9997
}
10098

10199
// Login to a Deis controller.
102-
func (d DeisCmd) Login(controller string, username string, password string, sslVerify bool) error {
100+
func (d *DeisCmd) Login(controller string, username string, password string, sslVerify bool) error {
103101
c, err := deis.New(sslVerify, controller, "")
104102

105103
if err != nil {
@@ -109,7 +107,7 @@ func (d DeisCmd) Login(controller string, username string, password string, sslV
109107
// Set user agent for temporary client.
110108
c.UserAgent = settings.UserAgent
111109

112-
if err = c.CheckConnection(); checkAPICompatibility(c, err, d.WErr) != nil {
110+
if err = c.CheckConnection(); d.checkAPICompatibility(c, err) != nil {
113111
return err
114112
}
115113

@@ -129,11 +127,11 @@ func (d DeisCmd) Login(controller string, username string, password string, sslV
129127
}
130128

131129
s := settings.Settings{Client: c}
132-
return doLogin(d.ConfigFile, s, username, password, d.WOut, d.WErr)
130+
return d.doLogin(s, username, password)
133131
}
134132

135133
// Logout from a Deis controller.
136-
func (d DeisCmd) Logout() error {
134+
func (d *DeisCmd) Logout() error {
137135
if err := settings.Delete(d.ConfigFile); err != nil {
138136
return err
139137
}
@@ -143,7 +141,7 @@ func (d DeisCmd) Logout() error {
143141
}
144142

145143
// Passwd changes a user's password.
146-
func (d DeisCmd) Passwd(username, password, newPassword string) error {
144+
func (d *DeisCmd) Passwd(username, password, newPassword string) error {
147145
s, err := settings.Load(d.ConfigFile)
148146

149147
if err != nil {
@@ -178,7 +176,7 @@ func (d DeisCmd) Passwd(username, password, newPassword string) error {
178176
}
179177

180178
err = auth.Passwd(s.Client, username, password, newPassword)
181-
if checkAPICompatibility(s.Client, err, d.WErr) != nil {
179+
if d.checkAPICompatibility(s.Client, err) != nil {
182180
d.PrintErr("Password change failed: ")
183181
return err
184182
}
@@ -188,7 +186,7 @@ func (d DeisCmd) Passwd(username, password, newPassword string) error {
188186
}
189187

190188
// Cancel deletes a user's account.
191-
func (d DeisCmd) Cancel(username, password string, yes bool) error {
189+
func (d *DeisCmd) Cancel(username, password string, yes bool) error {
192190
s, err := settings.Load(d.ConfigFile)
193191

194192
if err != nil {
@@ -234,7 +232,7 @@ func (d DeisCmd) Cancel(username, password string, yes bool) error {
234232
err = auth.Delete(s.Client, username)
235233
if err == deis.ErrConflict {
236234
return fmt.Errorf("%s still has applications associated with it. Transfer ownership or delete them first", username)
237-
} else if checkAPICompatibility(s.Client, err, d.WErr) != nil {
235+
} else if d.checkAPICompatibility(s.Client, err) != nil {
238236
return err
239237
}
240238

@@ -251,7 +249,7 @@ func (d DeisCmd) Cancel(username, password string, yes bool) error {
251249

252250
// Whoami prints the logged in user. If all is true, it fetches info from the controller to know
253251
// more about the user.
254-
func (d DeisCmd) Whoami(all bool) error {
252+
func (d *DeisCmd) Whoami(all bool) error {
255253
s, err := settings.Load(d.ConfigFile)
256254

257255
if err != nil {
@@ -271,15 +269,15 @@ func (d DeisCmd) Whoami(all bool) error {
271269
}
272270

273271
// Regenerate regenenerates a user's token.
274-
func (d DeisCmd) Regenerate(username string, all bool) error {
272+
func (d *DeisCmd) Regenerate(username string, all bool) error {
275273
s, err := settings.Load(d.ConfigFile)
276274

277275
if err != nil {
278276
return err
279277
}
280278

281279
token, err := auth.Regenerate(s.Client, username, all)
282-
if checkAPICompatibility(s.Client, err, d.WErr) != nil {
280+
if d.checkAPICompatibility(s.Client, err) != nil {
283281
return err
284282
}
285283

cmd/autoscale.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
)
77

88
// AutoscaleList tells the informations about app's autoscale status
9-
func (d DeisCmd) AutoscaleList(appID string) error {
9+
func (d *DeisCmd) AutoscaleList(appID string) error {
1010
s, appID, err := load(d.ConfigFile, appID)
1111

1212
if err != nil {
1313
return err
1414
}
1515

1616
appSettings, err := appsettings.List(s.Client, appID)
17-
if checkAPICompatibility(s.Client, err, d.WErr) != nil {
17+
if d.checkAPICompatibility(s.Client, err) != nil {
1818
return err
1919
}
2020

@@ -33,7 +33,7 @@ func (d DeisCmd) AutoscaleList(appID string) error {
3333
}
3434

3535
// AutoscaleSet sets autoscale options for the app.
36-
func (d DeisCmd) AutoscaleSet(appID string, processType string, min int, max int, CPUPercent int) error {
36+
func (d *DeisCmd) AutoscaleSet(appID string, processType string, min int, max int, CPUPercent int) error {
3737
s, appID, err := load(d.ConfigFile, appID)
3838

3939
if err != nil {
@@ -64,7 +64,7 @@ func (d DeisCmd) AutoscaleSet(appID string, processType string, min int, max int
6464
}
6565

6666
// AutoscaleUnset removes autoscale for the app.
67-
func (d DeisCmd) AutoscaleUnset(appID string, processType string) error {
67+
func (d *DeisCmd) AutoscaleUnset(appID string, processType string) error {
6868
s, appID, err := load(d.ConfigFile, appID)
6969

7070
if err != nil {

0 commit comments

Comments
 (0)