package completion
import (
"strings"
)
type RawValues []Candidate
func (c RawValues ) Filter (values ...string ) RawValues {
toremove := make (map [string ]bool )
for _ , v := range values {
toremove [v ] = true
}
filtered := make ([]Candidate , 0 )
for _ , rawValue := range c {
if _ , ok := toremove [rawValue .Value ]; !ok {
filtered = append (filtered , rawValue )
}
}
return filtered
}
func (c *Values ) Merge (other Values ) {
if other .Usage != "" {
c .Usage = other .Usage
}
c .NoSpace .Merge (other .NoSpace )
c .Messages .Merge (other .Messages )
for tag := range other .ListLong {
if _ , found := c .ListLong [tag ]; !found {
c .ListLong [tag ] = true
}
}
}
func (c RawValues ) EachTag (tagF func (tag string , values RawValues )) {
tags := make ([]string , 0 )
tagGroups := make (map [string ]RawValues )
for _ , val := range c {
if _ , exists := tagGroups [val .Tag ]; !exists {
tagGroups [val .Tag ] = make (RawValues , 0 )
tags = append (tags , val .Tag )
}
tagGroups [val .Tag ] = append (tagGroups [val .Tag ], val )
}
for _ , tag := range tags {
tagF (tag , tagGroups [tag ])
}
}
func (c RawValues ) FilterPrefix (prefix string , matchCase bool ) RawValues {
if prefix == "" {
return c
}
filtered := make (RawValues , 0 )
if !matchCase {
prefix = strings .ToLower (prefix )
}
for _ , raw := range c {
val := raw .Value
if !matchCase {
val = strings .ToLower (val )
}
if strings .HasPrefix (val , prefix ) {
filtered = append (filtered , raw )
}
}
return filtered
}
func (c RawValues ) Len () int { return len (c ) }
func (c RawValues ) Swap (i , j int ) { c [i ], c [j ] = c [j ], c [i ] }
func (c RawValues ) Less (i , j int ) bool {
return strings .ToLower (c [i ].Value ) < strings .ToLower (c [j ].Value )
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .