/
dump.go
46 lines (41 loc) · 833 Bytes
/
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
package cmd
import (
"fmt"
"path/filepath"
"github.com/davecgh/go-spew/spew"
"github.com/spf13/cobra"
"github.com/twpayne/go-vfs"
)
var dumpCommand = &cobra.Command{
Use: "dump",
Short: "Dump the target state",
RunE: makeRunE(config.runDumpCommand),
}
func init() {
rootCommand.AddCommand(dumpCommand)
}
func (c *Config) runDumpCommand(fs vfs.FS, command *cobra.Command, args []string) error {
targetState, err := c.getTargetState(fs)
if err != nil {
return err
}
if len(args) == 0 {
spew.Dump(targetState)
} else {
for _, arg := range args {
path, err := filepath.Abs(arg)
if err != nil {
return err
}
state, err := targetState.Get(path)
if err != nil {
return err
}
if state == nil {
return fmt.Errorf("%s: not found", arg)
}
spew.Dump(state)
}
}
return nil
}