3 // Predictor implements a predict method, in which given
4 // command line arguments returns a list of options it predicts.
5 type Predictor interface {
9 // PredictOr unions two predicate functions, so that the result predicate
10 // returns the union of their predication
11 func PredictOr(predictors ...Predictor) Predictor {
12 return PredictFunc(func(a Args) (prediction []string) {
13 for _, p := range predictors {
17 prediction = append(prediction, p.Predict(a)...)
23 // PredictFunc determines what terms can follow a command or a flag
24 // It is used for auto completion, given last - the last word in the already
25 // in the command line, what words can complete it.
26 type PredictFunc func(Args) []string
28 // Predict invokes the predict function and implements the Predictor interface
29 func (p PredictFunc) Predict(a Args) []string {
36 // PredictNothing does not expect anything after.
37 var PredictNothing Predictor
39 // PredictAnything expects something, but nothing particular, such as a number
41 var PredictAnything = PredictFunc(func(Args) []string { return nil })