summaryrefslogtreecommitdiff
path: root/complete.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-05 21:57:21 +0300
committerEyal Posener <[email protected]>2017-05-05 21:57:21 +0300
commit5e07cbd4c20a5a3bb5bc84148dc4d4ebffa3d033 (patch)
tree14562796afbc9b220836384339ae80403aa03076 /complete.go
parent6311b602abc0f3c0a854c244fca147101b623eba (diff)
Add file completion flag
Diffstat (limited to 'complete.go')
-rw-r--r--complete.go19
1 files changed, 6 insertions, 13 deletions
diff --git a/complete.go b/complete.go
index eedaa81..6345e63 100644
--- a/complete.go
+++ b/complete.go
@@ -13,23 +13,19 @@ const (
type Completer struct {
Command
- log func(format string, args ...interface{})
}
func New(c Command) *Completer {
- return &Completer{
- Command: c,
- log: logger(),
- }
+ return &Completer{Command: c}
}
func (c *Completer) Complete() {
args := getLine()
- c.log("Completing args: %s", args)
+ logger("Completing args: %s", args)
options := c.complete(args)
- c.log("Completion: %s", options)
+ logger("Completion: %s", options)
output(options)
}
@@ -38,13 +34,10 @@ func (c *Completer) complete(args []string) []string {
return c.chooseRelevant(last(args), all)
}
-func (c *Completer) chooseRelevant(last string, list []string) (opts []string) {
- if last == "" {
- return list
- }
+func (c *Completer) chooseRelevant(last string, list []Option) (options []string) {
for _, sub := range list {
- if strings.HasPrefix(sub, last) {
- opts = append(opts, sub)
+ if sub.Matches(last) {
+ options = append(options, sub.String())
}
}
return