Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comments are not stripped when a command is decorated by "cmd2.with_argparser" #1287

Open
gjvc opened this issue Dec 30, 2023 · 1 comment
Open

Comments

@gjvc
Copy link

gjvc commented Dec 30, 2023

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

@kmvanbrunt
Copy link
Member

kmvanbrunt commented Dec 30, 2023

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.
#631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants