mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-24 17:15:40 +00:00
debug: add an mtree.Debugf and -debug flag
Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
39f68f5be2
commit
ed6b293839
4 changed files with 26 additions and 3 deletions
|
@ -23,6 +23,8 @@ var (
|
||||||
flListKeywords = flag.Bool("list-keywords", false, "List the keywords available")
|
flListKeywords = flag.Bool("list-keywords", false, "List the keywords available")
|
||||||
flResultFormat = flag.String("result-format", "bsd", "output the validation results using the given format (bsd, json, path)")
|
flResultFormat = flag.String("result-format", "bsd", "output the validation results using the given format (bsd, json, path)")
|
||||||
flTar = flag.String("T", "", "use tar archive to create or validate a directory hierarchy spec")
|
flTar = flag.String("T", "", "use tar archive to create or validate a directory hierarchy spec")
|
||||||
|
|
||||||
|
flDebug = flag.Bool("debug", false, "output debug info to STDERR")
|
||||||
)
|
)
|
||||||
|
|
||||||
var formats = map[string]func(*mtree.Result) string{
|
var formats = map[string]func(*mtree.Result) string{
|
||||||
|
@ -57,6 +59,10 @@ var formats = map[string]func(*mtree.Result) string{
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *flDebug {
|
||||||
|
os.Setenv("DEBUG", "1")
|
||||||
|
}
|
||||||
|
|
||||||
// so that defers cleanly exec
|
// so that defers cleanly exec
|
||||||
var isErr bool
|
var isErr bool
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
18
debug.go
Normal file
18
debug.go
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package mtree
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DebugOutput is the where DEBUG output is written
|
||||||
|
var DebugOutput = os.Stderr
|
||||||
|
|
||||||
|
// Debugf does formatted output to DebugOutput, only if DEBUG environment variable is set
|
||||||
|
func Debugf(format string, a ...interface{}) (n int, err error) {
|
||||||
|
if os.Getenv("DEBUG") != "" {
|
||||||
|
return fmt.Fprintf(DebugOutput, "[%d] [DEBUG] %s\n", time.Now().UnixNano(), fmt.Sprintf(format, a...))
|
||||||
|
}
|
||||||
|
return 0, nil
|
||||||
|
}
|
|
@ -186,6 +186,7 @@ var (
|
||||||
// The keyword value is the SHA1 digest of the extended attribute's value.
|
// The keyword value is the SHA1 digest of the extended attribute's value.
|
||||||
// In this way, the order of the keys does not matter, and the contents of the value is not revealed.
|
// In this way, the order of the keys does not matter, and the contents of the value is not revealed.
|
||||||
"xattr": xattrKeywordFunc,
|
"xattr": xattrKeywordFunc,
|
||||||
|
"xattrs": xattrKeywordFunc,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
// +build linux
|
|
||||||
|
|
||||||
package mtree
|
package mtree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
Loading…
Reference in a new issue