-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathcmd_yaml.go
104 lines (88 loc) · 2.19 KB
/
cmd_yaml.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// Show a YAML file, interactively
//
package main
import (
"context"
"flag"
"fmt"
"io/ioutil"
"github.com/google/subcommands"
)
//
// The options set by our command-line flags.
//
type yamlCmd struct {
}
//
// Glue
//
func (*yamlCmd) Name() string { return "yaml" }
func (*yamlCmd) Synopsis() string { return "Show a summary of a YAML report." }
func (*yamlCmd) Usage() string {
return `yaml file1 file2 .. fileN:
Show a summary of the specified YAML reports.
`
}
//
// Flag setup: NOP
//
func (p *yamlCmd) SetFlags(f *flag.FlagSet) {
}
//
// YamlDump parses the given file, and then dumps appropriate information
// from the give report.
//
func YamlDump(file string) {
content, _ := ioutil.ReadFile(file)
node, err := ParsePuppetReport(content)
if err != nil {
fmt.Printf("Failed to read %s, %v\n", file, err)
return
}
fmt.Printf("Hostname: %s\n", node.Fqdn)
fmt.Printf("Reported: %s\n", node.At)
fmt.Printf("State : %s\n", node.State)
fmt.Printf("Runtime : %s\n", node.Runtime)
fmt.Printf("\nResources\n")
fmt.Printf("\tFailed : %s\n", node.Failed)
fmt.Printf("\tChanged: %s\n", node.Changed)
fmt.Printf("\tSkipped: %s\n", node.Skipped)
fmt.Printf("\tTotal : %s\n", node.Total)
if node.Failed != "0" {
fmt.Printf("\nFailed:\n")
for i := range node.ResourcesFailed {
fmt.Printf("\t%s\n", node.ResourcesFailed[i].Name)
fmt.Printf("\t\t%s:%s\n", node.ResourcesFailed[i].File, node.ResourcesFailed[i].Line)
}
}
if node.Changed != "0" {
fmt.Printf("\nChanged:\n")
for i := range node.ResourcesChanged {
fmt.Printf("\t%s\n", node.ResourcesChanged[i].Name)
fmt.Printf("\t\t%s:%s\n", node.ResourcesChanged[i].File, node.ResourcesChanged[i].Line)
}
}
if node.Skipped != "0" {
fmt.Printf("\nSkipped:\n")
for i := range node.ResourcesSkipped {
fmt.Printf("\t%s\n", node.ResourcesSkipped[i].Name)
fmt.Printf("\t\t%s:%s\n", node.ResourcesSkipped[i].File, node.ResourcesSkipped[i].Line)
}
}
}
//
// Entry-point.
//
func (p *yamlCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
//
// Show each file.
//
for _, arg := range f.Args() {
YamlDump(arg)
}
//
// All done.
//
return subcommands.ExitSuccess
}