-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathmtas_command.go
More file actions
71 lines (61 loc) · 2.15 KB
/
mtas_command.go
File metadata and controls
71 lines (61 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package commands
import (
"flag"
"code.cloudfoundry.org/cli/v8/cf/terminal"
"code.cloudfoundry.org/cli/v8/plugin"
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/baseclient"
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/ui"
"github.com/cloudfoundry-incubator/multiapps-cli-plugin/util"
)
// MtasCommand is a command for listing all deployed MTAs
type MtasCommand struct {
*BaseCommand
}
func NewMtasCommand() *MtasCommand {
baseCmd := &BaseCommand{flagsParser: NewDefaultCommandFlagsParser(nil), flagsValidator: NewDefaultCommandFlagsValidator(nil)}
mtasCmd := &MtasCommand{baseCmd}
baseCmd.Command = mtasCmd
return mtasCmd
}
// GetPluginCommand returns the plugin command details
func (c *MtasCommand) GetPluginCommand() plugin.Command {
return plugin.Command{
Name: "mtas",
HelpText: "List all multi-target apps",
UsageDetails: plugin.Usage{
Usage: "cf mtas [-u URL]" + util.BaseEnvHelpText,
Options: map[string]string{
deployServiceURLOpt: "Deploy service URL, by default 'deploy-service.<system-domain>'",
},
},
}
}
func (c *MtasCommand) defineCommandOptions(flags *flag.FlagSet) {
//no additional options to define
}
func (c *MtasCommand) executeInternal(positionalArgs []string, dsHost string, flags *flag.FlagSet, cfTarget util.CloudFoundryTarget) ExecutionStatus {
// Print initial message
ui.Say("Getting multi-target apps in org %s / space %s as %s...",
terminal.EntityNameColor(cfTarget.Org.Name), terminal.EntityNameColor(cfTarget.Space.Name),
terminal.EntityNameColor(cfTarget.Username))
// Create new REST client
mtaV2Client := c.NewMtaV2Client(dsHost, cfTarget)
// Get all deployed components
mtas, err := mtaV2Client.GetMtasForThisSpace(nil, nil)
if err != nil {
ui.Failed("Could not get deployed components: %s", baseclient.NewClientError(err))
return Failure
}
ui.Ok()
// Print all deployed MTAs
if len(mtas) > 0 {
table := ui.Table([]string{"mta id", "version", "namespace"})
for _, mta := range mtas {
table.Add(mta.Metadata.ID, util.GetMtaVersionAsString(mta), mta.Metadata.Namespace)
}
table.Print()
} else {
ui.Say("No multi-target apps found")
}
return Success
}