Skip to content

Commit

Permalink
add --sort flag
Browse files Browse the repository at this point in the history
  • Loading branch information
shihyuho committed Oct 21, 2019
1 parent 4998baf commit 5eff35e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/dockerctl/addr_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"github.com/sirupsen/logrus"
"github.com/softleader/dockerctl/pkg/dockerd"
"github.com/spf13/cobra"
"sort"
)

const nodeAddrDesc = `List addr of all running node
`

type addrNodeCmd struct {
force bool
sort bool
}

func newAddrNodeCmd() *cobra.Command {
Expand All @@ -26,6 +28,7 @@ func newAddrNodeCmd() *cobra.Command {

f := cmd.Flags()
f.BoolVarP(&c.force, "force", "f", c.force, "force to evict the node cache")
f.BoolVar(&c.sort, "sort", c.sort, "sort the addr")

return cmd
}
Expand All @@ -35,8 +38,15 @@ func (c *addrNodeCmd) run() (err error) {
if err != nil {
return err
}
var addrs []string
for _, node := range nodes {
logrus.Println(node.Addr)
addrs = append(addrs, node.Addr)
}
if c.sort {
sort.Strings(addrs)
}
for _, addr := range addrs {
logrus.Println(addr)
}
return nil
}

0 comments on commit 5eff35e

Please sign in to comment.