predict files: extract predictFiles function

This commit is contained in:
Eyal Posener 2017-05-11 22:19:23 +03:00
parent 200b1b5b69
commit 026906bf10
1 changed files with 39 additions and 33 deletions

View File

@ -26,12 +26,18 @@ func PredictFiles(pattern string) Predictor {
func files(pattern string, allowFiles bool) PredictFunc { func files(pattern string, allowFiles bool) PredictFunc {
return func(a Args) (prediction []string) { return func(a Args) (prediction []string) {
if strings.HasSuffix(a.Last, "/..") { prediction = predictFiles(a.Last, pattern, allowFiles)
return return
} }
dir := dirFromLast(a.Last) }
func predictFiles(last string, pattern string, allowFiles bool) (prediction []string) {
if strings.HasSuffix(last, "/..") {
return
}
dir := dirFromLast(last)
rel := !filepath.IsAbs(pattern) rel := !filepath.IsAbs(pattern)
Log("looking for files in %s (last=%s)", dir, a.Last)
files := listFiles(dir, pattern) files := listFiles(dir, pattern)
// get wording directory for relative name // get wording directory for relative name
@ -55,12 +61,12 @@ func files(pattern string, allowFiles bool) PredictFunc {
} }
// test matching of file to the argument // test matching of file to the argument
if match.File(f, a.Last) { if match.File(f, last) {
prediction = append(prediction, f) prediction = append(prediction, f)
} }
} }
return return
}
} }
func listFiles(dir, pattern string) []string { func listFiles(dir, pattern string) []string {