diff options
author | kotfu <kotfu@kotfu.net> | 2018-07-15 16:20:53 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-07-15 16:20:53 -0600 |
commit | 152499771620e3625d1c86463a2b676e4d0d87f7 (patch) | |
tree | aafeb8f845cb7a0ccc9a1b33571770f7caa474c4 /cmd2/cmd2.py | |
parent | 13cfc585837cf1170c6528a5970d0dbeccd78ce1 (diff) | |
download | cmd2-git-152499771620e3625d1c86463a2b676e4d0d87f7.tar.gz |
Add usage warning to preparse() for #417
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 946182c9..45f3da60 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1642,10 +1642,20 @@ class Cmd(cmd.Cmd): # noinspection PyMethodMayBeStatic def preparse(self, raw: str) -> str: - """Hook method executed just before the command line is interpreted, but after the input prompt is generated. + """Hook method executed before user input is parsed. - :param raw: raw command line input - :return: potentially modified raw command line input + WARNING: If it's a multiline command, `preparse()` may not get all the + user input. _complete_statement() really does two things: a) parse the + user input, and b) accept more input in case it's a multiline command + the passed string doesn't have a terminator. `preparse()` is currently + called before we know whether it's a multiline command, and before we + know whether the user input includes a termination character. + + If you want a reliable pre parsing hook method, register a postparsing + hook, modify the user input, and then reparse it. + + :param raw: raw command line input :return: potentially modified raw + command line input """ return raw |