-
Notifications
You must be signed in to change notification settings - Fork 291
/
command_completers.go
53 lines (44 loc) · 988 Bytes
/
command_completers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
// (C) Copyright 2022 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package main
import (
"io/fs"
"path/filepath"
"strings"
)
const (
defMntPrefix = "/mnt"
)
func listDir(match string) (result []string) {
if strings.HasSuffix(match, "vos-") {
match = filepath.Dir(match)
}
filepath.Walk(match, func(path string, info fs.FileInfo, err error) error {
if err != nil {
/* ignore error */
return nil
}
if strings.Contains(path, "vos-") {
result = append(result, path)
}
return nil
})
return
}
func openCompleter(prefix string, args []string) []string {
suggestions := []string{"-h", "-w", "--write_mode"}
suggestions = append(suggestions, listDir(defMntPrefix)...)
if len(prefix) > 0 {
var newSuggestions []string
for _, s := range suggestions {
if strings.HasPrefix(s, prefix) {
newSuggestions = append(newSuggestions, strings.Trim(s, prefix))
}
}
suggestions = newSuggestions
}
return suggestions
}