@@ -2,6 +2,7 @@ package cmd
22
33import (
44 "fmt"
5+ "io"
56 "os"
67 "strings"
78 "time"
@@ -23,26 +24,26 @@ func (d DeisCmd) AppCreate(id, buildpack, remote string, noRemote bool) error {
2324 return err
2425 }
2526
26- fmt .Print ("Creating Application... " )
27- quit := progress ()
27+ d .Print ("Creating Application... " )
28+ quit := progress (d . WOut )
2829 app , err := apps .New (s .Client , id )
2930
3031 quit <- true
3132 <- quit
3233
33- if checkAPICompatibility (s .Client , err ) != nil {
34+ if checkAPICompatibility (s .Client , err , d . WErr ) != nil {
3435 return err
3536 }
3637
37- fmt .Printf ("done, created %s\n " , app .ID )
38+ d .Printf ("done, created %s\n " , app .ID )
3839
3940 if buildpack != "" {
4041 configValues := api.Config {
4142 Values : map [string ]interface {}{
4243 "BUILDPACK_URL" : buildpack ,
4344 },
4445 }
45- if _ , err = config .Set (s .Client , app .ID , configValues ); checkAPICompatibility (s .Client , err ) != nil {
46+ if _ , err = config .Set (s .Client , app .ID , configValues ); checkAPICompatibility (s .Client , err , d . WErr ) != nil {
4647 return err
4748 }
4849 }
@@ -57,11 +58,11 @@ func (d DeisCmd) AppCreate(id, buildpack, remote string, noRemote bool) error {
5758 return err
5859 }
5960
60- fmt .Printf (remoteCreationMsg , remote , app .ID )
61+ d .Printf (remoteCreationMsg , remote , app .ID )
6162 }
6263
6364 if noRemote {
64- fmt .Printf ("If you want to add a git remote for this app later, use `deis git:remote -a %s`\n " , app .ID )
65+ d .Printf ("If you want to add a git remote for this app later, use `deis git:remote -a %s`\n " , app .ID )
6566 }
6667
6768 return nil
@@ -80,14 +81,14 @@ func (d DeisCmd) AppsList(results int) error {
8081 }
8182
8283 apps , count , err := apps .List (s .Client , results )
83- if checkAPICompatibility (s .Client , err ) != nil {
84+ if checkAPICompatibility (s .Client , err , d . WErr ) != nil {
8485 return err
8586 }
8687
87- fmt .Printf ("=== Apps%s" , limitCount (len (apps ), count ))
88+ d .Printf ("=== Apps%s" , limitCount (len (apps ), count ))
8889
8990 for _ , app := range apps {
90- fmt .Println (app .ID )
91+ d .Println (app .ID )
9192 }
9293 return nil
9394}
@@ -101,11 +102,11 @@ func (d DeisCmd) AppInfo(appID string) error {
101102 }
102103
103104 app , err := apps .Get (s .Client , appID )
104- if checkAPICompatibility (s .Client , err ) != nil {
105+ if checkAPICompatibility (s .Client , err , d . WErr ) != nil {
105106 return err
106107 }
107108
108- url , err := appURL (s , appID )
109+ url , err := appURL (s , appID , d . WErr )
109110 if err != nil {
110111 return err
111112 }
@@ -114,27 +115,27 @@ func (d DeisCmd) AppInfo(appID string) error {
114115 url = fmt .Sprintf (noDomainAssignedMsg , appID )
115116 }
116117
117- fmt .Printf ("=== %s Application\n " , app .ID )
118- fmt .Println ("updated: " , app .Updated )
119- fmt .Println ("uuid: " , app .UUID )
120- fmt .Println ("created: " , app .Created )
121- fmt .Println ("url: " , url )
122- fmt .Println ("owner: " , app .Owner )
123- fmt .Println ("id: " , app .ID )
118+ d .Printf ("=== %s Application\n " , app .ID )
119+ d .Println ("updated: " , app .Updated )
120+ d .Println ("uuid: " , app .UUID )
121+ d .Println ("created: " , app .Created )
122+ d .Println ("url: " , url )
123+ d .Println ("owner: " , app .Owner )
124+ d .Println ("id: " , app .ID )
124125
125- fmt .Println ()
126+ d .Println ()
126127 // print the app processes
127128 if err = d .PsList (app .ID , defaultLimit ); err != nil {
128129 return err
129130 }
130131
131- fmt .Println ()
132+ d .Println ()
132133 // print the app domains
133134 if err = d .DomainsList (app .ID , defaultLimit ); err != nil {
134135 return err
135136 }
136137
137- fmt .Println ()
138+ d .Println ()
138139
139140 return nil
140141}
@@ -147,7 +148,7 @@ func (d DeisCmd) AppOpen(appID string) error {
147148 return err
148149 }
149150
150- u , err := appURL (s , appID )
151+ u , err := appURL (s , appID , d . WErr )
151152 if err != nil {
152153 return err
153154 }
@@ -172,7 +173,7 @@ func (d DeisCmd) AppLogs(appID string, lines int) error {
172173 }
173174
174175 logs , err := apps .Logs (s .Client , appID , lines )
175- if checkAPICompatibility (s .Client , err ) != nil {
176+ if checkAPICompatibility (s .Client , err , d . WErr ) != nil {
176177 return err
177178 }
178179
@@ -191,17 +192,17 @@ func (d DeisCmd) AppRun(appID, command string) error {
191192 return err
192193 }
193194
194- fmt .Printf ("Running '%s'...\n " , command )
195+ d .Printf ("Running '%s'...\n " , command )
195196
196197 out , err := apps .Run (s .Client , appID , command )
197- if checkAPICompatibility (s .Client , err ) != nil {
198+ if checkAPICompatibility (s .Client , err , d . WErr ) != nil {
198199 return err
199200 }
200201
201202 if out .ReturnCode == 0 {
202- fmt .Print (out .Output )
203+ d .Print (out .Output )
203204 } else {
204- fmt . Fprint ( os . Stderr , out .Output )
205+ d . PrintErr ( out .Output )
205206 }
206207
207208 os .Exit (out .ReturnCode )
@@ -229,7 +230,7 @@ func (d DeisCmd) AppDestroy(appID, confirm string) error {
229230 }
230231
231232 if confirm == "" {
232- fmt .Printf (` ! WARNING: Potentially Destructive Action
233+ d .Printf (` ! WARNING: Potentially Destructive Action
233234 ! This command will destroy the application: %s
234235 ! To proceed, type "%s" or re-run this command with --confirm=%s
235236
@@ -243,13 +244,13 @@ func (d DeisCmd) AppDestroy(appID, confirm string) error {
243244 }
244245
245246 startTime := time .Now ()
246- fmt .Printf ("Destroying %s...\n " , appID )
247+ d .Printf ("Destroying %s...\n " , appID )
247248
248- if err = apps .Delete (s .Client , appID ); checkAPICompatibility (s .Client , err ) != nil {
249+ if err = apps .Delete (s .Client , appID ); checkAPICompatibility (s .Client , err , d . WErr ) != nil {
249250 return err
250251 }
251252
252- fmt .Printf ("done in %ds\n " , int (time .Since (startTime ).Seconds ()))
253+ d .Printf ("done in %ds\n " , int (time .Since (startTime ).Seconds ()))
253254
254255 if gitSession {
255256 return d .GitRemove (appID )
@@ -266,24 +267,24 @@ func (d DeisCmd) AppTransfer(appID, username string) error {
266267 return err
267268 }
268269
269- fmt .Printf ("Transferring %s to %s... " , appID , username )
270+ d .Printf ("Transferring %s to %s... " , appID , username )
270271
271272 err = apps .Transfer (s .Client , appID , username )
272- if checkAPICompatibility (s .Client , err ) != nil {
273+ if checkAPICompatibility (s .Client , err , d . WErr ) != nil {
273274 return err
274275 }
275276
276- fmt .Println ("done" )
277+ d .Println ("done" )
277278
278279 return nil
279280}
280281
281282const noDomainAssignedMsg = "No domain assigned to %s"
282283
283284// appURL grabs the first domain an app has and returns this.
284- func appURL (s * settings.Settings , appID string ) (string , error ) {
285+ func appURL (s * settings.Settings , appID string , wErr io. Writer ) (string , error ) {
285286 domains , _ , err := domains .List (s .Client , appID , 1 )
286- if checkAPICompatibility (s .Client , err ) != nil {
287+ if checkAPICompatibility (s .Client , err , wErr ) != nil {
287288 return "" , err
288289 }
289290
0 commit comments