aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/posener/complete/readme.md
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/posener/complete/readme.md')
-rw-r--r--vendor/github.com/posener/complete/readme.md116
1 files changed, 116 insertions, 0 deletions
diff --git a/vendor/github.com/posener/complete/readme.md b/vendor/github.com/posener/complete/readme.md
new file mode 100644
index 0000000..74077e3
--- /dev/null
+++ b/vendor/github.com/posener/complete/readme.md
@@ -0,0 +1,116 @@
1# complete
2
3[![Build Status](https://travis-ci.org/posener/complete.svg?branch=master)](https://travis-ci.org/posener/complete)
4[![codecov](https://codecov.io/gh/posener/complete/branch/master/graph/badge.svg)](https://codecov.io/gh/posener/complete)
5[![GoDoc](https://godoc.org/github.com/posener/complete?status.svg)](http://godoc.org/github.com/posener/complete)
6[![Go Report Card](https://goreportcard.com/badge/github.com/posener/complete)](https://goreportcard.com/report/github.com/posener/complete)
7
8A tool for bash writing bash completion in go.
9
10Writing bash completion scripts is a hard work. This package provides an easy way
11to create bash completion scripts for any command, and also an easy way to install/uninstall
12the completion of the command.
13
14## go command bash completion
15
16In [gocomplete](./gocomplete) there is an example for bash completion for the `go` command line.
17
18This is an example that uses the `complete` package on the `go` command - the `complete` package
19can also be used to implement any completions, see [Usage](#usage).
20
21### Install
22
231. Type in your shell:
24```
25go get -u github.com/posener/complete/gocomplete
26gocomplete -install
27```
28
292. Restart your shell
30
31Uninstall by `gocomplete -uninstall`
32
33### Features
34
35- Complete `go` command, including sub commands and all flags.
36- Complete packages names or `.go` files when necessary.
37- Complete test names after `-run` flag.
38
39## complete package
40
41Supported shells:
42
43- [x] bash
44- [x] zsh
45
46### Usage
47
48Assuming you have program called `run` and you want to have bash completion
49for it, meaning, if you type `run` then space, then press the `Tab` key,
50the shell will suggest relevant complete options.
51
52In that case, we will create a program called `runcomplete`, a go program,
53with a `func main()` and so, that will make the completion of the `run`
54program. Once the `runcomplete` will be in a binary form, we could
55`runcomplete -install` and that will add to our shell all the bash completion
56options for `run`.
57
58So here it is:
59
60```go
61import "github.com/posener/complete"
62
63func main() {
64
65 // create a Command object, that represents the command we want
66 // to complete.
67 run := complete.Command{
68
69 // Sub defines a list of sub commands of the program,
70 // this is recursive, since every command is of type command also.
71 Sub: complete.Commands{
72
73 // add a build sub command
74 "build": complete.Command {
75
76 // define flags of the build sub command
77 Flags: complete.Flags{
78 // build sub command has a flag '-cpus', which
79 // expects number of cpus after it. in that case
80 // anything could complete this flag.
81 "-cpus": complete.PredictAnything,
82 },
83 },
84 },
85
86 // define flags of the 'run' main command
87 Flags: complete.Flags{
88 // a flag -o, which expects a file ending with .out after
89 // it, the tab completion will auto complete for files matching
90 // the given pattern.
91 "-o": complete.PredictFiles("*.out"),
92 },
93
94 // define global flags of the 'run' main command
95 // those will show up also when a sub command was entered in the
96 // command line
97 GlobalFlags: complete.Flags{
98
99 // a flag '-h' which does not expects anything after it
100 "-h": complete.PredictNothing,
101 },
102 }
103
104 // run the command completion, as part of the main() function.
105 // this triggers the autocompletion when needed.
106 // name must be exactly as the binary that we want to complete.
107 complete.New("run", run).Run()
108}
109```
110
111### Self completing program
112
113In case that the program that we want to complete is written in go we
114can make it self completing.
115
116Here is an [example](./example/self/main.go)