diff options
| author | kotfu <kotfu@kotfu.net> | 2019-07-16 17:28:14 -0600 |
|---|---|---|
| committer | kotfu <kotfu@kotfu.net> | 2019-07-16 17:28:14 -0600 |
| commit | a8c4a65106ad6325adec5e662ee8a5397527dba5 (patch) | |
| tree | 835188fe74653be5bf38ad3fa265d614b4882db6 /docs/features/completion.rst | |
| parent | eb882b2b308bb2e09761a74007ea308b489c2d56 (diff) | |
| download | cmd2-git-a8c4a65106ad6325adec5e662ee8a5397527dba5.tar.gz | |
Integrate freefeatures into new doc structure
Diffstat (limited to 'docs/features/completion.rst')
| -rw-r--r-- | docs/features/completion.rst | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/docs/features/completion.rst b/docs/features/completion.rst index c89b24cc..5d2a722c 100644 --- a/docs/features/completion.rst +++ b/docs/features/completion.rst @@ -1,4 +1,33 @@ Completion ========== -How tab completion works and how to implement it in your own project +``cmd2`` adds tab-completion of file system paths for all built-in commands +where it makes sense, including: + +- ``edit`` +- ``run_pyscript`` +- ``run_script`` +- ``shell`` + +``cmd2`` also adds tab-completion of shell commands to the ``shell`` command. + +Additionally, it is trivial to add identical file system path completion to +your own custom commands. Suppose you have defined a custom command ``foo`` by +implementing the ``do_foo`` method. To enable path completion for the ``foo`` +command, then add a line of code similar to the following to your class which +inherits from ``cmd2.Cmd``:: + + complete_foo = self.path_complete + +This will effectively define the ``complete_foo`` readline completer method in +your class and make it utilize the same path completion logic as the built-in +commands. + +The built-in logic allows for a few more advanced path completion capabilities, +such as cases where you only want to match directories. Suppose you have a +custom command ``bar`` implemented by the ``do_bar`` method. You can enable +path completion of directories only for this command by adding a line of code +similar to the following to your class which inherits from ``cmd2.Cmd``:: + + # Make sure you have an "import functools" somewhere at the top + complete_bar = functools.partialmethod(cmd2.Cmd.path_complete, path_filter=os.path.isdir) |
