@@ -11,6 +11,7 @@ import (
1111 "github.com/deis/controller-sdk-go/api"
1212 "github.com/deis/controller-sdk-go/apps"
1313 "github.com/deis/controller-sdk-go/config"
14+ "github.com/deis/controller-sdk-go/domains"
1415 "github.com/deis/workflow-cli/pkg/git"
1516 "github.com/deis/workflow-cli/pkg/webbrowser"
1617 "github.com/deis/workflow-cli/settings"
@@ -104,11 +105,20 @@ func AppInfo(appID string) error {
104105 return err
105106 }
106107
108+ url , err := appURL (s , appID )
109+ if err != nil {
110+ return err
111+ }
112+
113+ if url == "" {
114+ url = fmt .Sprintf (noDomainAssignedMsg , appID )
115+ }
116+
107117 fmt .Printf ("=== %s Application\n " , app .ID )
108118 fmt .Println ("updated: " , app .Updated )
109119 fmt .Println ("uuid: " , app .UUID )
110120 fmt .Println ("created: " , app .Created )
111- fmt .Println ("url: " , app . URL )
121+ fmt .Println ("url: " , url )
112122 fmt .Println ("owner: " , app .Owner )
113123 fmt .Println ("id: " , app .ID )
114124
@@ -137,12 +147,15 @@ func AppOpen(appID string) error {
137147 return err
138148 }
139149
140- app , err := apps . Get ( s . Client , appID )
141- if checkAPICompatibility ( s . Client , err ) != nil {
150+ u , err := appURL ( s , appID )
151+ if err != nil {
142152 return err
143153 }
144154
145- u := app .URL
155+ if u == "" {
156+ return fmt .Errorf (noDomainAssignedMsg , appID )
157+ }
158+
146159 if ! (strings .HasPrefix (u , "http://" ) || strings .HasPrefix (u , "https://" )) {
147160 u = "http://" + u
148161 }
@@ -276,3 +289,32 @@ func AppTransfer(appID, username string) error {
276289
277290 return nil
278291}
292+
293+ const noDomainAssignedMsg = "No domain assigned to %s"
294+
295+ // appURL grabs the first domain an app has and returns this.
296+ func appURL (s * settings.Settings , appID string ) (string , error ) {
297+ domains , _ , err := domains .List (s .Client , appID , 1 )
298+ if checkAPICompatibility (s .Client , err ) != nil {
299+ return "" , err
300+ }
301+
302+ if len (domains ) == 0 {
303+ return "" , nil
304+ }
305+
306+ return expandURL (s .Client .ControllerURL .Host , domains [0 ].Domain ), nil
307+ }
308+
309+ // expandURL expands an app url if neccessary.
310+ func expandURL (host , u string ) string {
311+ if strings .Contains (u , "." ) {
312+ // If domain is a full url.
313+ return u
314+ }
315+
316+ // If domain is a subdomain, look up the controller url and replace the subdomain.
317+ parts := strings .Split (host , "." )
318+ parts [0 ] = u
319+ return strings .Join (parts , "." )
320+ }
0 commit comments