enhanced list

pull/2/head
iwilltry42 6 years ago
parent e4029d09aa
commit 1f417ce948
  1. 23
      config.go
  2. 11
      go.mod
  3. 31
      go.sum
  4. 12
      main.go
  5. 43
      vendor/modules.txt

@ -1,13 +1,15 @@
package main
import (
"fmt"
"context"
"io/ioutil"
"log"
"os"
"path"
dockerClient "github.com/docker/docker/client"
"github.com/mitchellh/go-homedir"
"github.com/olekukonko/tablewriter"
)
// createDirIfNotExists checks for the existence of a directory and creates it along with all required parents if not.
@ -47,16 +49,27 @@ func getClusterDir(name string) (string, error) {
}
// printClusters prints the names of existing clusters
func printClusters() {
func printClusters(all bool) {
clusters, err := getClusters()
if err != nil {
log.Fatalf("ERROR: Couldn't list clusters -> %+v", err)
}
fmt.Println("NAME")
// TODO: user docker client to get state of cluster
docker, err := dockerClient.NewEnvClient()
if err != nil {
log.Printf("WARNING: couldn't get docker info -> %+v", err)
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"NAME", "IMAGE", "STATUS"})
for _, cluster := range clusters {
fmt.Println(cluster)
containerInfo, _ := docker.ContainerInspect(context.Background(), cluster)
clusterData := []string{cluster, containerInfo.Config.Image, containerInfo.ContainerJSONBase.State.Status}
if containerInfo.ContainerJSONBase.State.Status == "running" || all {
table.Append(clusterData)
}
}
table.Render()
}
// getClusters returns a list of cluster names which are folder names in the config directory

@ -3,6 +3,17 @@ module github.com/iwilltry42/k3d-go
go 1.12
require (
github.com/Microsoft/go-winio v0.4.12 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.13.1
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.3.3 // indirect
github.com/mattn/go-runewidth v0.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/olekukonko/tablewriter v0.0.1
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/stretchr/testify v1.3.0 // indirect
github.com/urfave/cli v1.20.0
golang.org/x/net v0.0.0-20190403144856-b630fd6fe46b // indirect
)

@ -1,4 +1,35 @@
github.com/Microsoft/go-winio v0.4.12 h1:xAfWHN1IrQ0NJ9TBC0KBZoqLjzDTr1ML+4MywiUOryc=
github.com/Microsoft/go-winio v0.4.12/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v1.13.1 h1:IkZjBSIc8hBjLpqeAbeE5mca5mNgeatLHBy3GO78BWo=
github.com/docker/docker v1.13.1/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88=
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190403144856-b630fd6fe46b h1:/zjbcJPEGAyu6Is/VBOALsgdi4z9+kz/Vtdm6S+beD0=
golang.org/x/net v0.0.0-20190403144856-b630fd6fe46b/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

@ -96,7 +96,7 @@ func startCluster(c *cli.Context) error {
// listClusters prints a list of created clusters
func listClusters(c *cli.Context) error {
printClusters()
printClusters(c.Bool("all"))
return nil
}
@ -222,8 +222,14 @@ func main() {
},
{
// list prints a list of created clusters
Name: "list",
Usage: "List all clusters",
Name: "list",
Usage: "List all clusters",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "all, a",
Usage: "also show non-running clusters",
},
},
Action: listClusters,
},
{

43
vendor/modules.txt vendored

@ -1,4 +1,47 @@
# github.com/Microsoft/go-winio v0.4.12
github.com/Microsoft/go-winio
# github.com/docker/distribution v2.7.1+incompatible
github.com/docker/distribution/reference
github.com/docker/distribution/digestset
# github.com/docker/docker v1.13.1
github.com/docker/docker/client
github.com/docker/docker/api/types
github.com/docker/docker/api/types/container
github.com/docker/docker/api/types/events
github.com/docker/docker/api/types/filters
github.com/docker/docker/api/types/network
github.com/docker/docker/api/types/reference
github.com/docker/docker/api/types/registry
github.com/docker/docker/api/types/swarm
github.com/docker/docker/api/types/time
github.com/docker/docker/api/types/versions
github.com/docker/docker/api/types/volume
github.com/docker/docker/pkg/tlsconfig
github.com/docker/docker/api/types/mount
github.com/docker/docker/api/types/blkiodev
github.com/docker/docker/api/types/strslice
# github.com/docker/go-connections v0.4.0
github.com/docker/go-connections/sockets
github.com/docker/go-connections/tlsconfig
github.com/docker/go-connections/nat
# github.com/docker/go-units v0.3.3
github.com/docker/go-units
# github.com/mattn/go-runewidth v0.0.4
github.com/mattn/go-runewidth
# github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/go-homedir
# github.com/olekukonko/tablewriter v0.0.1
github.com/olekukonko/tablewriter
# github.com/opencontainers/go-digest v1.0.0-rc1
github.com/opencontainers/go-digest
# github.com/pkg/errors v0.8.1
github.com/pkg/errors
# github.com/urfave/cli v1.20.0
github.com/urfave/cli
# golang.org/x/net v0.0.0-20190403144856-b630fd6fe46b
golang.org/x/net/context
golang.org/x/net/context/ctxhttp
golang.org/x/net/proxy
golang.org/x/net/internal/socks
# golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a
golang.org/x/sys/windows

Loading…
Cancel
Save