-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcmd_dump.go
69 lines (57 loc) · 1.24 KB
/
cmd_dump.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
// Dump
//
// The dump sub-command dumps the (parsed) configuration file(s)
package main
import (
"context"
"flag"
"fmt"
"github.com/google/subcommands"
"github.com/skx/overseer/parser"
"github.com/skx/overseer/test"
)
type dumpCmd struct {
}
//
// Glue
//
func (*dumpCmd) Name() string { return "dump" }
func (*dumpCmd) Synopsis() string { return "Dump a parsed configuration file" }
func (*dumpCmd) Usage() string {
return `dump :
Dump a parsed configuration file.
This is particularly useful to show the result of macro-expansion.
`
}
//
// Flag setup.
//
func (p *dumpCmd) SetFlags(f *flag.FlagSet) {
}
//
// This is a callback invoked by the parser when a job
// has been successfully parsed.
//
func dumpTest(tst test.Test) error {
fmt.Printf("%s\n", tst.Input)
return nil
}
//
// Entry-point.
//
func (p *dumpCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
for _, file := range f.Args() {
//
// Create an object to parse our file.
//
helper := parser.New()
//
// For each parsed job call `dump_test` to show it
//
err := helper.ParseFile(file, dumpTest)
if err != nil {
fmt.Printf("Error parsing file: %s\n", err.Error())
}
}
return subcommands.ExitSuccess
}