Exemple #1
0
func listCmd(c *cli.Context) {
	data := [][]string{}
	stackMap, err := stackManager.SearchContainers(c.String("if"), c.String("tf"), c.String("cf"))
	if err != nil {
		util.Log.Fatalln(err)
	}

	for stackKey, containers := range stackMap {
		for _, c := range containers {
			var ports string
			for key, val := range c.PublicPorts() {
				ports = ports + strconv.FormatInt(val, 10) + "->" + strconv.FormatInt(key, 10) + " "
			}
			data = append(data, []string{stackKey, c.ContainerSwarmNode(), c.ContainerName(), c.ContainerImageName(), c.ContainerState(), ports})
		}
	}

	table := tablewriter.NewWriter(os.Stdout)
	table.SetHeader([]string{"Stack", "Node", "Name", "Image", "Status", "Ports"})

	for _, v := range data {
		table.Append(v)
	}
	table.Render()
}