diff options
| author | Eyal Posener <[email protected]> | 2017-05-06 08:24:17 +0300 |
|---|---|---|
| committer | Eyal Posener <[email protected]> | 2017-05-06 09:27:51 +0300 |
| commit | d33bac720bcaf13a5ee9f6f165293183d2e3e24d (patch) | |
| tree | f65d42c434e6b67f53431c0c33c30d0c66774abd /complete.go | |
| parent | 5dbf53eec0f066e97f443d1d85e1ba9ee288f1b5 (diff) | |
Remove Complete struct
Diffstat (limited to 'complete.go')
| -rw-r--r-- | complete.go | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/complete.go b/complete.go deleted file mode 100644 index 302486c..0000000 --- a/complete.go +++ /dev/null @@ -1,66 +0,0 @@ -package complete - -import ( - "fmt" - "os" - "strings" -) - -const ( - envComplete = "COMP_LINE" - envDebug = "COMP_DEBUG" -) - -type Completer struct { - Command -} - -func New(c Command) *Completer { - return &Completer{Command: c} -} - -func (c *Completer) Complete() { - args := getLine() - Log("Completing args: %s", args) - - options := c.complete(args) - - Log("Completion: %s", options) - output(options) -} - -func (c *Completer) complete(args []string) []string { - all, _ := c.options(args[:len(args)-1]) - return c.chooseRelevant(last(args), all) -} - -func (c *Completer) chooseRelevant(last string, options []Option) (relevant []string) { - for _, option := range options { - if option.Matches(last) { - relevant = append(relevant, option.String()) - } - } - return -} - -func getLine() []string { - line := os.Getenv(envComplete) - if line == "" { - panic("should be run as a complete script") - } - return strings.Split(line, " ") -} - -func last(args []string) (last string) { - if len(args) > 0 { - last = args[len(args)-1] - } - return -} - -func output(options []string) { - // stdout of program defines the complete options - for _, option := range options { - fmt.Println(option) - } -} |
