diff options
| author | Eyal Posener <[email protected]> | 2017-05-20 08:13:13 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-20 08:13:13 +0300 |
| commit | 6fc235c5dce6994778c731e552da9cf02e74a121 (patch) | |
| tree | 7d81e7271b9e869ba26a4be9a3dc8841c41f9bf0 /predict_files.go | |
| parent | 238b78ffd98aa3cfefc48964efc208b8bc376a95 (diff) | |
predict files: remove loop
Diffstat (limited to 'predict_files.go')
| -rw-r--r-- | predict_files.go | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/predict_files.go b/predict_files.go index 4b8c84a..c8adf7e 100644 --- a/predict_files.go +++ b/predict_files.go @@ -30,29 +30,21 @@ func files(pattern string, allowFiles bool) PredictFunc { // if only one directory has matched the result, search recursively into // this directory to give more results. return func(a Args) (prediction []string) { - for { + prediction = predictFiles(a, pattern, allowFiles) - prediction = predictFiles(a, pattern, allowFiles) - - // if the number of prediction is not 1, we either have many results or - // have no results, so we return it. - if len(prediction) != 1 { - return - } - - // if the result is only one item, we might want to recursively check - // for more accurate results. - if prediction[0] == a.Last { - return - } - - // only try deeper, if the one item is a directory - if stat, err := os.Stat(prediction[0]); err != nil || !stat.IsDir() { - return - } + // if the number of prediction is not 1, we either have many results or + // have no results, so we return it. + if len(prediction) != 1 { + return + } - a.Last = prediction[0] + // only try deeper, if the one item is a directory + if stat, err := os.Stat(prediction[0]); err != nil || !stat.IsDir() { + return } + + a.Last = prediction[0] + return predictFiles(a, pattern, allowFiles) } } |
