summaryrefslogtreecommitdiff
path: root/docs/source/complete.rst
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@gmail.com>2013-11-12 18:02:55 -0500
committerDoug Hellmann <doug.hellmann@gmail.com>2013-11-12 18:02:55 -0500
commit82e28c2e99c80890e409335137009876c45225a2 (patch)
tree9bd8e713fd0c5404f6bc9d01fd5eb5e542b5db77 /docs/source/complete.rst
parent8077b6f1c8bb7e6ca7fa619d609947704603b62e (diff)
parent60361edf68cf5822d96e215d71fe14260df01ec4 (diff)
downloadcliff-82e28c2e99c80890e409335137009876c45225a2.tar.gz
Merge commit '60361edf68cf5822d96e215d71fe14260df01ec4' into completion
# By Terry Howe # Via Doug Hellmann (1) and Terry Howe (1) * commit '60361edf68cf5822d96e215d71fe14260df01ec4': code style fixes code style fixes various python code optimizations; shuffle I/O to shell classes add bash complete
Diffstat (limited to 'docs/source/complete.rst')
-rw-r--r--docs/source/complete.rst45
1 files changed, 45 insertions, 0 deletions
diff --git a/docs/source/complete.rst b/docs/source/complete.rst
new file mode 100644
index 0000000..2a08098
--- /dev/null
+++ b/docs/source/complete.rst
@@ -0,0 +1,45 @@
+====================
+ Command Completion
+====================
+
+A generic command completion command is available to generate a
+bash-completion script. Currently, the command will generate a script
+for bash versions 3 or 4. There is also a mode that generates only
+data that can be used in your own script. The command completion script
+is generated based on the commands and options that you have specified
+in cliff.
+
+Usage
+=====
+
+In order for your command to support command completions, you need to
+add the `cliff.complete.CompleteCommand` class to your command manager.
+
+::
+
+ self.command_manager.add_command('complete', cliff.complete.CompleteCommand)
+
+When you run the command, it will generate a bash-completion script:
+
+::
+
+ (.venv)$ mycmd complete
+ _mycmd()
+ {
+ local cur prev words
+ COMPREPLY=()
+ _get_comp_words_by_ref -n : cur prev words
+
+ # Command data:
+ cmds='agent aggregate backup'
+ cmds_agent='--name'
+ ...
+ if [ -z "${completed}" ] ; then
+ COMPREPLY=( $( compgen -f -- "$cur" ) $( compgen -d -- "$cur" ) )
+ else
+ COMPREPLY=( $(compgen -W "${completed}" -- ${cur}) )
+ fi
+ return 0
+ }
+ complete -F _mycmd mycmd
+