RfidResearchGroup / ChameleonUltra

The new generation chameleon based on NRF52840 makes the performance of card emulation more stable. And gave the chameleon the ability to read, write, and decrypt cards.
https://chameleonultra.com
GNU General Public License v3.0
897 stars 148 forks source link

Corrected wrong text when colorizing argparse help #182

Closed aenigma-es closed 11 months ago

aenigma-es commented 11 months ago

When wrong arguments were used, the CLI would fail for an assert that was expecting a different text.

Changed: "options:" to "optional arguments:"

github-actions[bot] commented 11 months ago

You are welcome to add an entry to the CHANGELOG.md as well

github-actions[bot] commented 11 months ago

Built artifacts for commit fdabd17be0717b53a0a045d51cbd8a34779a99cc

Firmware

Client

doegox commented 11 months ago

Hmm the current code works fine on my machine while your patch provokes an exception

Traceback (most recent call last):
  File "/home/phil/devel/00smartcard/readers/ChameleonUltra/ChameleonUltra.git/software/script/chameleon_cli_main.py", line 121, in exec_cmd
    args_parse_result = args.parse_args(arg_list)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/argparse.py", line 1881, in parse_args
    args, argv = self.parse_known_args(args, namespace)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/argparse.py", line 1914, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/argparse.py", line 2154, in _parse_known_args
    self.error(_('the following arguments are required: %s') %
  File "/home/phil/devel/00smartcard/readers/ChameleonUltra/ChameleonUltra.git/software/script/chameleon_utils.py", line 53, in error
    raise ArgsParserError('%(prog)s: error: %(message)s\n' % args)
chameleon_utils.ArgsParserError: hw slot change: error: the following arguments are required: -s/--slot

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/phil/devel/00smartcard/readers/ChameleonUltra/ChameleonUltra.git/software/script/chameleon_cli_main.py", line 186, in <module>
    ChameleonCLI().startCLI()
  File "/home/phil/devel/00smartcard/readers/ChameleonUltra/ChameleonUltra.git/software/script/chameleon_cli_main.py", line 178, in startCLI
    self.exec_cmd(cmd_str)
  File "/home/phil/devel/00smartcard/readers/ChameleonUltra/ChameleonUltra.git/software/script/chameleon_cli_main.py", line 123, in exec_cmd
    args.print_help()
  File "/home/phil/devel/00smartcard/readers/ChameleonUltra/ChameleonUltra.git/software/script/chameleon_utils.py", line 91, in print_help
    assert options[0].strip() == 'optional arguments:'
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I think the text comes from the argparse module. What is your versions of argparse and of python?

aenigma-es commented 11 months ago

So the problem is caused by different argparse versions.

I'm using Python 3.9.2 and argparse 1.1 They are from a standard install of a Debian 11

$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>> print(argparse.__version__)
1.1
>>> exit()
doegox commented 11 months ago

Strange, I've python 3.11.6 and argparse 1.1 Let's get the code catch both variants...

doegox commented 11 months ago

I pushed a fix, does it work for you @aenigma-es ?

aenigma-es commented 11 months ago

It's working perfectly. Thanks