1
1
package v7
2
2
3
3
import (
4
+ "code.cloudfoundry.org/cli/actor/v7action"
4
5
"code.cloudfoundry.org/cli/command/flag"
5
6
"code.cloudfoundry.org/cli/command/v7/shared"
6
7
)
7
8
9
+ type AppDisplayer interface {
10
+ AppDisplay (summary v7action.DetailedApplicationSummary , displayStartCommand bool )
11
+ }
12
+
8
13
type AppCommand struct {
9
14
BaseCommand
10
15
11
16
RequiredArgs flag.AppName `positional-args:"yes"`
12
17
GUID bool `long:"guid" description:"Retrieve and display the given app's guid. All other health and status output for the app is suppressed."`
13
18
usage interface {} `usage:"CF_NAME app APP_NAME [--guid]"`
14
19
relatedCommands interface {} `related_commands:"apps, events, logs, map-route, unmap-route, push"`
20
+ JSONOutput bool `long:"json" description:"Output in json form"`
15
21
}
16
22
17
23
func (cmd AppCommand ) Execute (args []string ) error {
@@ -29,15 +35,18 @@ func (cmd AppCommand) Execute(args []string) error {
29
35
return err
30
36
}
31
37
32
- cmd .UI .DisplayTextWithFlavor ("Showing health and status for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}..." , map [string ]interface {}{
33
- "AppName" : cmd .RequiredArgs .AppName ,
34
- "OrgName" : cmd .Config .TargetedOrganization ().Name ,
35
- "SpaceName" : cmd .Config .TargetedSpace ().Name ,
36
- "Username" : user .Name ,
37
- })
38
- cmd .UI .DisplayNewline ()
38
+ var appSummaryDisplayer AppDisplayer = shared .NewAppSummaryJSONDisplayer (cmd .UI )
39
+ if ! cmd .JSONOutput {
40
+ cmd .UI .DisplayTextWithFlavor ("Showing health and status for app {{.AppName}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}..." , map [string ]interface {}{
41
+ "AppName" : cmd .RequiredArgs .AppName ,
42
+ "OrgName" : cmd .Config .TargetedOrganization ().Name ,
43
+ "SpaceName" : cmd .Config .TargetedSpace ().Name ,
44
+ "Username" : user .Name ,
45
+ })
46
+ cmd .UI .DisplayNewline ()
47
+ appSummaryDisplayer = shared .NewAppSummaryDisplayer (cmd .UI )
48
+ }
39
49
40
- appSummaryDisplayer := shared .NewAppSummaryDisplayer (cmd .UI )
41
50
summary , warnings , err := cmd .Actor .GetDetailedAppSummary (cmd .RequiredArgs .AppName , cmd .Config .TargetedSpace ().GUID , false )
42
51
cmd .UI .DisplayWarnings (warnings )
43
52
if err != nil {
@@ -55,6 +64,10 @@ func (cmd AppCommand) displayAppGUID() error {
55
64
return err
56
65
}
57
66
67
+ if cmd .JSONOutput {
68
+ return cmd .UI .DisplayJSON ("" , map [string ]string {"guid" : app .GUID })
69
+ }
70
+
58
71
cmd .UI .DisplayText (app .GUID )
59
72
return nil
60
73
}
0 commit comments