cmd2
cmd2 copied to clipboard
comments are not stripped when a command is decorated by "cmd2.with_argparser"
summary
when a do_ command is decorated with @cmd2.with_argparser it does not correctly remove trailing comments.
For example:
@cmd2.with_argparser( system_argument_parser )
def do_system( self, args: argparse.Namespace ):
do_system( args, self._model )
and given the command:
(no system selected) > system select <TAB>
almalinux-9.3 centos-7 darwin-22 debian-12 ubuntu-22.04
(no system selected) > system select almalinux-9.3 # hello
Usage: system {list, select, image, container} ...
Error: unrecognized arguments: # hello
(no system selected) >
We get the "unrecognized arguments" error.
This seems to be corrected by this change:
diff --git a/cmd2/parsing.py b/cmd2/parsing.py
index fc28b634..0c39eca3 100755
--- a/cmd2/parsing.py
+++ b/cmd2/parsing.py
@@ -35,7 +35,7 @@ def shlex_split(str_to_split: str) -> List[str]:
:param str_to_split: the string being split
:return: A list of tokens
"""
- return shlex.split(str_to_split, comments=False, posix=False)
+ return shlex.split(str_to_split, comments=True, posix=False)
version python 3.12, cmd2 2.4.3
cmd2 does not support embedded comments by design. https://cmd2.readthedocs.io/en/latest/features/scripting.html#comments
You can read the reasoning and discussion behind it here. https://github.com/python-cmd2/cmd2/pull/631