Added bash completion support.
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Tue, 6 Mar 2018 15:47:13 +0000 (16:47 +0100)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Tue, 6 Mar 2018 15:47:13 +0000 (16:47 +0100)
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
conf.d/etc/bash_completion.d/xds-cli [new file with mode: 0644]
main.go

diff --git a/conf.d/etc/bash_completion.d/xds-cli b/conf.d/etc/bash_completion.d/xds-cli
new file mode 100644 (file)
index 0000000..9778180
--- /dev/null
@@ -0,0 +1,12 @@
+#! /bin/bash
+
+_cli_bash_autocomplete() {
+     local cur opts base
+     COMPREPLY=()
+     cur="${COMP_WORDS[COMP_CWORD]}"
+     opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
+     COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+     return 0
+ }
+
+complete -F _cli_bash_autocomplete xds-cli
diff --git a/main.go b/main.go
index 7d1f5e1..a6f8104 100644 (file)
--- a/main.go
+++ b/main.go
@@ -141,6 +141,7 @@ func main() {
        app.Metadata["version"] = AppVersion
        app.Metadata["git-tag"] = AppSubVersion
        app.Metadata["logger"] = Log
+       app.EnableBashCompletion = true
 
        // Create env vars help
        dynDesc := "\nENVIRONMENT VARIABLES:"