From 119cdc314c1614cbc72210f290ce23007706edf7 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Thu, 21 Jul 2016 08:12:30 +1000 Subject: [PATCH] cmd: add --result-format=path format This allows for shell callers to just get a simple diff of what files changed between the two invocations of go-mtree. This is somewhat similar to supplying -f twice to the BSD mtree (though that compares two specs and also gives you information about what *kind* of change occurred). Signed-off-by: Aleksa Sarai --- cmd/gomtree/main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/gomtree/main.go b/cmd/gomtree/main.go index cbc2ff9..3352ba6 100644 --- a/cmd/gomtree/main.go +++ b/cmd/gomtree/main.go @@ -32,6 +32,7 @@ var formats = map[string]func(*mtree.Result) string{ return buffer.String() }, + // Outputs the full result struct in JSON. "json": func(r *mtree.Result) string { var buffer bytes.Buffer if err := json.NewEncoder(&buffer).Encode(r); err != nil { @@ -39,6 +40,15 @@ var formats = map[string]func(*mtree.Result) string{ } return buffer.String() }, + + // Outputs only the paths which failed to validate. + "path": func(r *mtree.Result) string { + var buffer bytes.Buffer + for _, fail := range r.Failures { + fmt.Fprintln(&buffer, fail.Path) + } + return buffer.String() + }, } func main() {