gomtree: -list-used
can output JSON
Piggybacking on `-result-format`: ```bash $ tar c .git/ | gomtree -c -T - > git.mtree $ gomtree -result-format=json -list-used -f ./git.mtree { "./git.mtree": [ "type", "mode", "uid", "gid", "tar_time", "size" ] } $ tar c .git/ | gomtree -c -T - -K sha512digest > git.mtree $ gomtree -result-format=json -list-used -f ./git.mtree { "./git.mtree": [ "type", "mode", "uid", "gid", "tar_time", "size", "sha512digest" ] } ``` Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
parent
97a2505b8b
commit
6d8cd9fe4c
1 changed files with 19 additions and 6 deletions
|
@ -164,13 +164,26 @@ func main() {
|
||||||
isErr = true
|
isErr = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("Keywords used in [%s]:\n", *flFile)
|
usedKeywords := mtree.CollectUsedKeywords(dh)
|
||||||
for _, kw := range mtree.CollectUsedKeywords(dh) {
|
if *flResultFormat == "json" {
|
||||||
fmt.Printf(" %s", kw)
|
// if they're asking for json, give it to them
|
||||||
if _, ok := mtree.KeywordFuncs[kw]; !ok {
|
data := map[string][]string{*flFile: usedKeywords}
|
||||||
fmt.Print(" (unsupported)")
|
buf, err := json.MarshalIndent(data, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
defer os.Exit(1)
|
||||||
|
isErr = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(string(buf))
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Keywords used in [%s]:\n", *flFile)
|
||||||
|
for _, kw := range usedKeywords {
|
||||||
|
fmt.Printf(" %s", kw)
|
||||||
|
if _, ok := mtree.KeywordFuncs[kw]; !ok {
|
||||||
|
fmt.Print(" (unsupported)")
|
||||||
|
}
|
||||||
|
fmt.Printf("\n")
|
||||||
}
|
}
|
||||||
fmt.Printf("\n")
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue