aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/posener/complete/predict.go
diff options
context:
space:
mode:
authorAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
committerAlex Pilon <apilon@hashicorp.com>2019-02-22 18:24:37 -0500
commit15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch)
tree255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/posener/complete/predict.go
parent07971ca38143c5faf951d152fba370ddcbe26ad5 (diff)
downloadterraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst
terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/posener/complete/predict.go')
-rw-r--r--vendor/github.com/posener/complete/predict.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/github.com/posener/complete/predict.go b/vendor/github.com/posener/complete/predict.go
new file mode 100644
index 0000000..8207063
--- /dev/null
+++ b/vendor/github.com/posener/complete/predict.go
@@ -0,0 +1,41 @@
1package complete
2
3// Predictor implements a predict method, in which given
4// command line arguments returns a list of options it predicts.
5type Predictor interface {
6 Predict(Args) []string
7}
8
9// PredictOr unions two predicate functions, so that the result predicate
10// returns the union of their predication
11func PredictOr(predictors ...Predictor) Predictor {
12 return PredictFunc(func(a Args) (prediction []string) {
13 for _, p := range predictors {
14 if p == nil {
15 continue
16 }
17 prediction = append(prediction, p.Predict(a)...)
18 }
19 return
20 })
21}
22
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.
26type PredictFunc func(Args) []string
27
28// Predict invokes the predict function and implements the Predictor interface
29func (p PredictFunc) Predict(a Args) []string {
30 if p == nil {
31 return nil
32 }
33 return p(a)
34}
35
36// PredictNothing does not expect anything after.
37var PredictNothing Predictor
38
39// PredictAnything expects something, but nothing particular, such as a number
40// or arbitrary name.
41var PredictAnything = PredictFunc(func(Args) []string { return nil })