diff --git a/cmd/gomtree/main.go b/cmd/gomtree/main.go index d520dba..8af7f55 100644 --- a/cmd/gomtree/main.go +++ b/cmd/gomtree/main.go @@ -23,6 +23,7 @@ var ( flListKeywords = flag.Bool("list-keywords", false, "List the keywords available") 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") + flBsdKeywords = flag.Bool("bsd-keywords", false, "only operate on keywords that are supported by upstream mtree(8)") flDebug = flag.Bool("debug", false, "output debug info to STDERR") ) @@ -96,29 +97,46 @@ func main() { return } - var currentKeywords []string + var ( + tmpKeywords []string + currentKeywords []string + ) // -k if *flUseKeywords != "" { - currentKeywords = splitKeywordsArg(*flUseKeywords) - if !inSlice("type", currentKeywords) { - currentKeywords = append([]string{"type"}, currentKeywords...) + tmpKeywords = splitKeywordsArg(*flUseKeywords) + if !inSlice("type", tmpKeywords) { + tmpKeywords = append([]string{"type"}, tmpKeywords...) } } else { if *flTar != "" { - currentKeywords = mtree.DefaultTarKeywords[:] + tmpKeywords = mtree.DefaultTarKeywords[:] } else { - currentKeywords = mtree.DefaultKeywords[:] + tmpKeywords = mtree.DefaultKeywords[:] } } + // -K if *flAddKeywords != "" { for _, kw := range splitKeywordsArg(*flAddKeywords) { - if !inSlice(kw, currentKeywords) { - currentKeywords = append(currentKeywords, kw) + if !inSlice(kw, tmpKeywords) { + tmpKeywords = append(tmpKeywords, kw) } } } + // -bsd-keywords + if *flBsdKeywords { + for _, k := range tmpKeywords { + if mtree.Keyword(k).Bsd() { + currentKeywords = append(currentKeywords, k) + } else { + fmt.Fprintf(os.Stderr, "INFO: ignoring %q as it is not an upstream keyword\n", k) + } + } + } else { + currentKeywords = tmpKeywords + } + // -f var dh *mtree.DirectoryHierarchy if *flFile != "" && !*flCreate {