mirror of https://github.com/status-im/migrate.git
remove searchpath package
This commit is contained in:
parent
a45e244a71
commit
13acfe3e2e
|
@ -1,46 +0,0 @@
|
|||
package searchpath
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var searchpath []string
|
||||
|
||||
func SetSearchPath(paths ...string) {
|
||||
searchpath = paths
|
||||
}
|
||||
|
||||
func AppendSearchPath(path string) {
|
||||
searchpath = append(searchpath, path)
|
||||
}
|
||||
|
||||
func PrependSearchPath(path string) {
|
||||
searchpath = append((searchpath)[:0], append([]string{path}, (searchpath)[0:]...)...)
|
||||
}
|
||||
|
||||
func GetSearchPath() []string {
|
||||
return searchpath
|
||||
}
|
||||
|
||||
// FindPath scans files in the search paths and
|
||||
// returns the path where the regex matches at least twice
|
||||
func FindPath(regex *regexp.Regexp) (path string, err error) {
|
||||
count := 0
|
||||
for _, path := range searchpath {
|
||||
// TODO refactor ioutil.ReadDir to read only first files per dir
|
||||
files, err := ioutil.ReadDir(path)
|
||||
if err == nil {
|
||||
for _, file := range files {
|
||||
if regex.MatchString(file.Name()) {
|
||||
count += 1
|
||||
}
|
||||
if count >= 2 {
|
||||
return path, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", errors.New("no path found")
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package searchpath
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSetSearchPath(t *testing.T) {
|
||||
SetSearchPath("a")
|
||||
if len(searchpath) != 1 || searchpath[0] != "a" {
|
||||
t.Error("SetSearchPath failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAppendSearchPath(t *testing.T) {
|
||||
SetSearchPath("a")
|
||||
AppendSearchPath("b")
|
||||
if len(searchpath) != 2 || searchpath[0] != "a" || searchpath[1] != "b" {
|
||||
t.Error("AppendSearchPath failed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrependSearchPath(t *testing.T) {
|
||||
SetSearchPath("a")
|
||||
PrependSearchPath("b")
|
||||
if len(searchpath) != 2 || searchpath[0] != "b" || searchpath[1] != "a" {
|
||||
t.Error("PrependSearchPath failed")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue