From 5e07cbd4c20a5a3bb5bc84148dc4d4ebffa3d033 Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Fri, 5 May 2017 21:57:21 +0300 Subject: Add file completion flag --- complete.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'complete.go') 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 -- cgit v1.2.3