mirror of https://github.com/rwxrob/bonzai
Add initial comp.File completer
parent
2cb365f0fa
commit
cf1e15abff
@ -0,0 +1,28 @@
|
||||
// Copyright 2022 Robert S. Muhlestein.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package comp
|
||||
|
||||
import (
|
||||
"github.com/rwxrob/bonzai/filter"
|
||||
"github.com/rwxrob/bonzai/util"
|
||||
)
|
||||
|
||||
// Files returns all file names for the directory and file prefix
|
||||
// passed. If nothing is passed assumes the current working directory.
|
||||
func Files(x Command, args ...string) []string {
|
||||
match := ""
|
||||
|
||||
if args != nil && len(args) > 0 {
|
||||
match = args[0]
|
||||
}
|
||||
|
||||
list := []string{}
|
||||
|
||||
// TODO if file separators detected, drill down to the proper
|
||||
// directory then check the leaf as the prefix of files
|
||||
|
||||
list = append(list, util.Files(match)...)
|
||||
|
||||
return filter.HasPrefix(list, match)
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
// Copyright 2022 Robert S. Muhlestein.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package comp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/rwxrob/bonzai/comp"
|
||||
)
|
||||
|
||||
func ExampleFiles() {
|
||||
os.Chdir("testdata/files")
|
||||
defer os.Chdir("../..")
|
||||
fmt.Println(comp.Files(nil))
|
||||
//Output:
|
||||
// [bar blah come foo other]
|
||||
}
|
Loading…
Reference in New Issue