mirror of
https://github.com/vbatts/go-mtree.git
synced 2024-11-25 17:45:39 +00:00
*: add --result-format=json format
This is far easier to parse than the default raw format, and provides the full serialised result structure. Signed-off-by: Aleksa Sarai <asarai@suse.de>
This commit is contained in:
parent
8cf7253132
commit
692f56a830
2 changed files with 15 additions and 5 deletions
11
check.go
11
check.go
|
@ -9,15 +9,16 @@ import (
|
||||||
|
|
||||||
// Result of a Check
|
// Result of a Check
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Failures []Failure // list of any failures in the Check
|
// list of any failures in the Check
|
||||||
|
Failures []Failure `json:"failures"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Failure of a particular keyword for a path
|
// Failure of a particular keyword for a path
|
||||||
type Failure struct {
|
type Failure struct {
|
||||||
Path string
|
Path string `json:"path"`
|
||||||
Keyword string
|
Keyword string `json:"keyword"`
|
||||||
Expected string
|
Expected string `json:"expected"`
|
||||||
Got string
|
Got string `json:"got"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a "pretty" formatting for a Failure
|
// String returns a "pretty" formatting for a Failure
|
||||||
|
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
@ -30,6 +31,14 @@ var formats = map[string]func(*mtree.Result) string{
|
||||||
}
|
}
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"json": func(r *mtree.Result) string {
|
||||||
|
var buffer bytes.Buffer
|
||||||
|
if err := json.NewEncoder(&buffer).Encode(r); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return buffer.String()
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
Loading…
Reference in a new issue