mirror of
https://github.com/cheat/cheat.git
synced 2024-11-10 21:26:49 +01:00
20 lines
416 B
Go
20 lines
416 B
Go
|
package cheatpath
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
// Filter filters all cheatpaths that are not named `name`
|
||
|
func Filter(paths []Cheatpath, name string) ([]Cheatpath, error) {
|
||
|
|
||
|
// if a path of the given name exists, return it
|
||
|
for _, path := range paths {
|
||
|
if path.Name == name {
|
||
|
return []Cheatpath{path}, nil
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// otherwise, return an error
|
||
|
return []Cheatpath{}, fmt.Errorf("cheatpath does not exist: %s", name)
|
||
|
}
|