summaryrefslogtreecommitdiff
path: root/command.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-06 21:04:11 +0300
committerGitHub <[email protected]>2017-05-06 21:04:11 +0300
commit2b6aed2b1e974a733c0dc614a9617c33a54c208c (patch)
treed9f9de0148c079071095e96c1033c39f0c898de1 /command.go
parent07b98cb91243293e26564058a78f28b83aa81cd4 (diff)
parent9963a854946be0603f9e79ccba0a8b2688b20053 (diff)
Merge pull request #3 from posener/predicate-as-function-type
Predicate as function type
Diffstat (limited to 'command.go')
-rw-r--r--command.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/command.go b/command.go
index 7bc0fc5..eac9dde 100644
--- a/command.go
+++ b/command.go
@@ -2,13 +2,13 @@ package complete
type Commands map[string]Command
-type Flags map[string]*Predicate
+type Flags map[string]Predicate
type Command struct {
Name string
Sub Commands
Flags Flags
- Args *Predicate
+ Args Predicate
}
// options returns all available complete options for the given command
@@ -17,11 +17,11 @@ func (c *Command) options(args []string) (options []Option, only bool) {
// remove the first argument, which is the command name
args = args[1:]
-
+ last := last(args)
// if prev has something that needs to follow it,
// it is the most relevant completion
- if predicate, ok := c.Flags[last(args)]; ok && predicate != nil {
- return predicate.predict(), true
+ if predicate, ok := c.Flags[last]; ok && predicate != nil {
+ return predicate.predict(last), true
}
sub, options, only := c.searchSub(args)
@@ -41,7 +41,7 @@ func (c *Command) options(args []string) (options []Option, only bool) {
}
// add additional expected argument of the command
- options = append(options, c.Args.predict()...)
+ options = append(options, c.Args.predict(last)...)
return
}