Add initial comp.File completer

pull/53/head
rwxrob 2 years ago
parent 2cb365f0fa
commit cf1e15abff
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

@ -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…
Cancel
Save