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 <asarai@suse.de>
This commit is contained in:
Aleksa Sarai 2016-07-21 08:12:30 +10:00
parent 692f56a830
commit 119cdc314c
No known key found for this signature in database
GPG Key ID: 9E18AA267DDB8DB4
1 changed files with 10 additions and 0 deletions

View File

@ -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() {