summaryrefslogtreecommitdiff
path: root/command.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-11-04 10:21:41 +0200
committerEyal Posener <[email protected]>2017-11-04 10:51:40 +0200
commit7ee9623f2b5d4685a91a51d0823275754b4d3a0a (patch)
treef45cd54539dd9a03cbb5314bb6a9c0891d013712 /command.go
parent88e59760adaddb8276c9b15511302890690e2dae (diff)
Filter matches as a final stage
This simplifies the prediction logic writing, the predictor doesn't need to filter our according to line matching, instead it returns everything and the filtering is done at the end. This does not break current behavior.
Diffstat (limited to 'command.go')
-rw-r--r--command.go17
1 files changed, 5 insertions, 12 deletions
diff --git a/command.go b/command.go
index 6de48e9..82d37d5 100644
--- a/command.go
+++ b/command.go
@@ -1,7 +1,5 @@
package complete
-import "github.com/posener/complete/match"
-
// Command represents a command line
// It holds the data that enables auto completion of command line
// Command can also be a sub command.
@@ -25,9 +23,9 @@ type Command struct {
}
// Predict returns all possible predictions for args according to the command struct
-func (c *Command) Predict(a Args) (predictions []string) {
- predictions, _ = c.predict(a)
- return
+func (c *Command) Predict(a Args) []string {
+ options, _ := c.predict(a)
+ return options
}
// Commands is the type of Sub member, it maps a command name to a command struct
@@ -36,9 +34,7 @@ type Commands map[string]Command
// Predict completion of sub command names names according to command line arguments
func (c Commands) Predict(a Args) (prediction []string) {
for sub := range c {
- if match.Prefix(sub, a.Last) {
- prediction = append(prediction, sub)
- }
+ prediction = append(prediction, sub)
}
return
}
@@ -56,10 +52,7 @@ func (f Flags) Predict(a Args) (prediction []string) {
if flagHyphenStart && !lastHyphenStart {
continue
}
-
- if match.Prefix(flag, a.Last) {
- prediction = append(prediction, flag)
- }
+ prediction = append(prediction, flag)
}
return
}