mirror of
https://github.com/vbatts/tar-split.git
synced 2024-11-16 13:28:37 +00:00
Merge pull request #54 from stephen679/keywords-used-list
hierarchy: provide option to list the used keywords in a spec
This commit is contained in:
commit
48e7ab8031
2 changed files with 54 additions and 11 deletions
|
@ -24,7 +24,7 @@ var (
|
||||||
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")
|
||||||
flBsdKeywords = flag.Bool("bsd-keywords", false, "only operate on keywords that are supported by upstream mtree(8)")
|
flBsdKeywords = flag.Bool("bsd-keywords", false, "only operate on keywords that are supported by upstream mtree(8)")
|
||||||
|
flListUsedKeywords = flag.Bool("list-used", false, "list all the keywords found in a validation manifest")
|
||||||
flDebug = flag.Bool("debug", false, "output debug info to STDERR")
|
flDebug = flag.Bool("debug", false, "output debug info to STDERR")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -156,6 +156,25 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -list-used
|
||||||
|
if *flListUsedKeywords {
|
||||||
|
if *flFile == "" {
|
||||||
|
log.Println("no specification provided. please provide a validation manifest")
|
||||||
|
defer os.Exit(1)
|
||||||
|
isErr = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("Keywords used in [%s]:\n", *flFile)
|
||||||
|
for _, kw := range mtree.CollectUsedKeywords(dh) {
|
||||||
|
fmt.Printf(" %s", kw)
|
||||||
|
if _, ok := mtree.KeywordFuncs[kw]; !ok {
|
||||||
|
fmt.Print(" (unsupported)")
|
||||||
|
}
|
||||||
|
fmt.Printf("\n")
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// -p <path>
|
// -p <path>
|
||||||
var rootPath = "."
|
var rootPath = "."
|
||||||
if *flPath != "" {
|
if *flPath != "" {
|
||||||
|
|
24
hierarchy.go
24
hierarchy.go
|
@ -25,3 +25,27 @@ func (dh DirectoryHierarchy) WriteTo(w io.Writer) (n int64, err error) {
|
||||||
}
|
}
|
||||||
return sum, nil
|
return sum, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CollectUsedKeywords collects and returns all the keywords used in a
|
||||||
|
// a DirectoryHierarchy
|
||||||
|
func CollectUsedKeywords(dh *DirectoryHierarchy) []string {
|
||||||
|
if dh != nil {
|
||||||
|
usedkeywords := []string{}
|
||||||
|
for _, e := range dh.Entries {
|
||||||
|
switch e.Type {
|
||||||
|
case FullType, RelativeType, SpecialType:
|
||||||
|
if e.Type != SpecialType || e.Name == "/set" {
|
||||||
|
kvs := e.Keywords
|
||||||
|
for _, kv := range kvs {
|
||||||
|
kw := KeyVal(kv).Keyword()
|
||||||
|
if !inSlice(kw, usedkeywords) {
|
||||||
|
usedkeywords = append(usedkeywords, kw)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return usedkeywords
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue