Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
lazartravica committed Apr 9, 2016
2 parents 2f590eb + 3d29481 commit bec63f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
38 changes: 35 additions & 3 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"io"
)

func cmdList(stdout io.Writer, stderr io.Writer, s *state) int {
groups := make(map[string]interface{}, 0)
func gatherResources(s *state) map[string][]string {
groups := make(map[string][]string, 0)
for _, res := range s.resources() {
for _, grp := range res.Groups() {
tmpGroup := []string{}
Expand All @@ -28,8 +28,40 @@ func cmdList(stdout io.Writer, stderr io.Writer, s *state) int {
groups["all"].(map[string]string)[out.keyName] = out.value
}
}
return groups
}

func cmdList(stdout io.Writer, stderr io.Writer, s *state) int {
return output(stdout, stderr, gatherResources(s))
}

func cmdInventory(stdout io.Writer, stderr io.Writer, s *state) int {
groups := gatherResources(s)
for group, res := range groups {

_, err := io.WriteString(stdout, "["+group+"]\n")
if err != nil {
fmt.Fprintf(stderr, "Error writing Invetory: %s\n", err)
return 1;
}

for _, ress := range res {

_, err := io.WriteString(stdout, ress + "\n")
if err != nil {
fmt.Fprintf(stderr, "Error writing Invetory: %s\n", err)
return 1;
}
}

_, err = io.WriteString(stdout, "\n")
if err != nil {
fmt.Fprintf(stderr, "Error writing Invetory: %s\n", err)
return 1;
}
}

return output(stdout, stderr, groups)
return 0;
}

func cmdHost(stdout io.Writer, stderr io.Writer, s *state, hostname string) int {
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
var version = flag.Bool("version", false, "print version information and exit")
var list = flag.Bool("list", false, "list mode")
var host = flag.String("host", "", "host mode")
var inventory = flag.Bool("inventory", false, "inventory mode")

func main() {
flag.Parse()
Expand Down Expand Up @@ -44,7 +45,7 @@ func main() {
os.Exit(1)
}

if !*list && *host == "" {
if !*list && *host == "" && !*inventory {
fmt.Fprint(os.Stderr, "Either --host or --list must be specified")
os.Exit(1)
}
Expand Down Expand Up @@ -72,6 +73,9 @@ func main() {
if *list {
os.Exit(cmdList(os.Stdout, os.Stderr, &s))

} else if *inventory {
os.Exit(cmdInventory(os.Stdout, os.Stderr, &s))

} else if *host != "" {
os.Exit(cmdHost(os.Stdout, os.Stderr, &s, *host))

Expand Down

0 comments on commit bec63f5

Please sign in to comment.