hierarchy: provide option to list the used keywords in a spec
To increase a user's control on how they validate a directory or tar archive with a specification, it is helpful to know which keywords are actually used in the spec provided. This way, the user can see what keywords to use or not use with the '-k' or '-K' flags. Signed-off-by: Stephen Chung <schung@redhat.com>
This commit is contained in:
parent
aa6d7c2c6e
commit
5372b5fc47
2 changed files with 54 additions and 11 deletions
24
hierarchy.go
24
hierarchy.go
|
@ -25,3 +25,27 @@ func (dh DirectoryHierarchy) WriteTo(w io.Writer) (n int64, err error) {
|
|||
}
|
||||
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…
Add table
Add a link
Reference in a new issue