predict files: extract predictFiles function
This commit is contained in:
parent
200b1b5b69
commit
026906bf10
|
@ -26,12 +26,18 @@ func PredictFiles(pattern string) Predictor {
|
|||
|
||||
func files(pattern string, allowFiles bool) PredictFunc {
|
||||
return func(a Args) (prediction []string) {
|
||||
if strings.HasSuffix(a.Last, "/..") {
|
||||
prediction = predictFiles(a.Last, pattern, allowFiles)
|
||||
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)
|
||||
Log("looking for files in %s (last=%s)", dir, a.Last)
|
||||
files := listFiles(dir, pattern)
|
||||
|
||||
// get wording directory for relative name
|
||||
|
@ -55,12 +61,12 @@ func files(pattern string, allowFiles bool) PredictFunc {
|
|||
}
|
||||
|
||||
// test matching of file to the argument
|
||||
if match.File(f, a.Last) {
|
||||
if match.File(f, last) {
|
||||
prediction = append(prediction, f)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func listFiles(dir, pattern string) []string {
|
||||
|
|
Loading…
Reference in New Issue