summaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-06 22:21:03 +0300
committerGitHub <[email protected]>2017-05-06 22:21:03 +0300
commitc26ef096c7990a5ae97b503545fd76ff6df388d6 (patch)
treed0180b667269b985d15520f3b2e1aafc9292af6e /example_test.go
parent2b6aed2b1e974a733c0dc614a9617c33a54c208c (diff)
parent404634e843081e7010260bd95006b84d6c40a8fd (diff)
Merge pull request #4 from posener/doc
Doc
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go
new file mode 100644
index 0000000..35664f3
--- /dev/null
+++ b/example_test.go
@@ -0,0 +1,46 @@
+package complete_test
+
+import "github.com/posener/complete"
+
+func main() {
+
+ // create a Command object, that represents the command we want
+ // to complete.
+ run := complete.Command{
+
+ // Name must be exactly as the binary that we want to complete
+ Name: "run",
+
+ // Sub defines a list of sub commands of the program,
+ // this is recursive, since every command is of type command also.
+ Sub: complete.Commands{
+
+ // add a build sub command
+ "build": complete.Command{
+
+ // define flags of the build sub command
+ Flags: complete.Flags{
+ // build sub command has a flag '-fast', which
+ // does not expects anything after it.
+ "-fast": complete.PredictNothing,
+ },
+ },
+ },
+
+ // define flags of the 'run' main command
+ Flags: complete.Flags{
+
+ // a flag '-h' which does not expects anything after it
+ "-h": complete.PredictNothing,
+
+ // a flag -o, which expects a file ending with .out after
+ // it, the tab completion will auto complete for files matching
+ // the given pattern.
+ "-o": complete.PredictFiles("*.out"),
+ },
+ }
+
+ // run the command completion, as part of the main() function.
+ // this triggers the autocompletion when needed.
+ complete.Run(run)
+}