-
Notifications
You must be signed in to change notification settings - Fork 3
/
output.go
48 lines (38 loc) · 1.06 KB
/
output.go
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
package main
import (
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/client"
"github.com/fatih/color"
"github.com/urfave/cli"
"golang.org/x/net/context"
)
func output(c *cli.Context) error {
stacks, err := getStacks(c)
if err != nil {
return err
}
swarm, swarmErr := client.NewEnvClient()
if swarmErr != nil {
return cli.NewExitError(swarmErr.Error(), 3)
}
for _, stack := range stacks {
filter := filters.NewArgs()
filter.Add("label", "com.docker.stack.namespace="+stack.Name)
services, servicesErr := swarm.ServiceList(context.Background(), types.ServiceListOptions{Filters: filter})
if servicesErr != nil {
return cli.NewExitError(servicesErr.Error(), 3)
}
current := getSwarmServicesSpecForStack(services)
for _, s := range current {
color.Green("%s\n", s.Spec.Name)
fmt.Println(" - Published Ports")
for _, port := range s.Endpoint.Ports {
fmt.Printf(" %d => %d\n", port.PublishedPort, port.TargetPort)
}
fmt.Println()
}
}
return nil
}