fix inconsistent behaviour of argparse-code

this affected certain versions of argparse in python3
This commit is contained in:
Patrick Kanzler 2016-07-17 19:17:10 +02:00
parent 9f5eed0020
commit a5cae3adb7
1 changed files with 6 additions and 0 deletions

View File

@ -456,7 +456,10 @@ def main():
# cli [subparser] -args # cli [subparser] -args
command_subparsers = parser.add_subparsers( command_subparsers = parser.add_subparsers(
title='ESCPOS Command', title='ESCPOS Command',
dest='parser',
) )
# fix inconsistencies in the behaviour of some versions of argparse
command_subparsers.required = False # force 'required' testing
# Build the ESCPOS command arguments # Build the ESCPOS command arguments
for command in ESCPOS_COMMANDS: for command in ESCPOS_COMMANDS:
@ -522,6 +525,9 @@ def main():
target_command = command_arguments.pop('func') target_command = command_arguments.pop('func')
# remove helper-argument 'parser' from dict
command_arguments.pop('parser', None)
if hasattr(printer, target_command): if hasattr(printer, target_command):
# print command with args # print command with args
getattr(printer, target_command)(**command_arguments) getattr(printer, target_command)(**command_arguments)