summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-05-28 22:50:15 -0600
committerkotfu <kotfu@kotfu.net>2018-05-28 22:50:15 -0600
commit7313fa467e6cb06e1f187dcbff2f643d13b4a0b2 (patch)
tree9c872784d63ac8ccb09bb613e45bc9ec975eed40
parent4e2749e8a41a8556a302a7d8f8316549c8558daa (diff)
parentf3676f23183451165185386a0ef5fc2ad910781e (diff)
downloadcmd2-git-7313fa467e6cb06e1f187dcbff2f643d13b4a0b2.tar.gz
Merge branch 'plugin_functions' of github.com:python-cmd2/cmd2 into plugin_functions
-rw-r--r--cmd2/cmd2.py3
-rw-r--r--docs/hooks.rst26
-rw-r--r--tasks.py2
3 files changed, 18 insertions, 13 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 9f2181d0..c117b05b 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -45,8 +45,7 @@ import pyperclip
from . import constants
from . import utils
-
-from cmd2.parsing import StatementParser, Statement
+from .parsing import StatementParser, Statement
# Set up readline
from .rl_utils import rl_type, RlType
diff --git a/docs/hooks.rst b/docs/hooks.rst
index 75febb2b..ed1d9070 100644
--- a/docs/hooks.rst
+++ b/docs/hooks.rst
@@ -110,7 +110,9 @@ Postparsing Hooks
Postparsing hooks are called after the user input has been parsed but before
execution of the comamnd. These hooks can be used to:
+
- modify the user input
+- run code before every command executes
- cancel execution of the current command
- exit the application
@@ -154,6 +156,7 @@ proper technique::
return stop, statement
If a postparsing hook returns ``True`` as the first value in the tuple:
+
- no more hooks of any kind (except command finalization hooks) will be called
- the command will not be executed
- no error message will be displayed to the user
@@ -165,7 +168,8 @@ Precommand Hooks
A precommand hook is defined in ``cmd.Cmd``. It is not able to request that the
app terminate, but it is passed the user input and allowed to make changes. If
-your hook needs to be able to exit the application, you should implement it as a postparsing hook.
+your hook needs to be able to exit the application, you should implement it as a
+postparsing hook.
Once output is redirected and the timer started, all the hooks registered with
``register_precmd_hook()`` are called. Here's how you do it::
@@ -181,15 +185,17 @@ Once output is redirected and the timer started, all the hooks registered with
You may choose to create a new ``Statement`` with different properties (see
above) or leave it alone, but you must return a ``Statement`` object.
-After all registered precommand hooks have been called, ``self.precmd(statement)``
-will be called. This retains full backwards compatibility with ``cmd.Cmd``.
+After all registered precommand hooks have been called,
+``self.precmd(statement)`` will be called. This retains full backwards
+compatibility with ``cmd.Cmd``.
Postcommand Hooks
^^^^^^^^^^^^^^^^^^
-Once the command method has returned (i.e. the ``do_command(self, statement) method``
-has been called and returns, all postcommand hooks are called. If output was redirected
-by the user, it is still redirected, and the command timer is still running.
+Once the command method has returned (i.e. the ``do_command(self, statement)
+method`` has been called and returns, all postcommand hooks are called. If
+output was redirected by the user, it is still redirected, and the command timer
+is still running.
Here's how to define a register a postcommand hook::
@@ -203,15 +209,15 @@ Here's how to define a register a postcommand hook::
return stop
Your hook will be passed the statement object, which describes the command which
-was executed. If your postcommand hook method gets called, you are guaranteed that
-the command method was called, and that it didn't raise an exception.
+was executed. If your postcommand hook method gets called, you are guaranteed
+that the command method was called, and that it didn't raise an exception.
If any postcommand hook raises an exception, no further postcommand hook methods
will be called.
After all registered precommand hooks have been called,
-``self.postcmd(statement)`` will be called. This retains full backwards
-compatibility with ``cmd.Cmd``.
+``self.postcmd(statement)`` will be called to retain full backward compatibility
+with ``cmd.Cmd``.
If any postcommand hook (registered or ``self.postcmd()``) returns ``True``,
subsequent postcommand hooks will still be called, as will the command
diff --git a/tasks.py b/tasks.py
index 000af0a5..6b552768 100644
--- a/tasks.py
+++ b/tasks.py
@@ -44,7 +44,7 @@ namespace.add_task(pytest)
def pytest_clean(context):
"Remove pytest cache and code coverage files and directories"
#pylint: disable=unused-argument
- dirs = ['.pytest-cache', '.cache', 'htmlcov', '.coverage']
+ dirs = ['.pytest_cache', '.cache', 'htmlcov', '.coverage']
rmrf(dirs)
namespace_clean.add_task(pytest_clean, 'pytest')