Add optional args_postprocessor.

This commit is contained in:
voussoir 2020-12-30 12:31:21 -08:00
parent 73f79af336
commit 593dfe5cb0

View file

@ -165,14 +165,18 @@ def subparser_betterhelp(parser, main_docstring, sub_docstrings):
# EASY MAINS
################################################################################
def single_main(argv, parser, docstring):
def single_main(argv, parser, docstring, args_postprocessor=None):
def main(argv):
args = parser.parse_args(argv)
if args_postprocessor is not None:
args = args_postprocessor(args)
return args.func(args)
return single_betterhelp(parser, docstring)(main)(argv)
def subparser_main(argv, parser, main_docstring, sub_docstrings):
def subparser_main(argv, parser, main_docstring, sub_docstrings, args_postprocessor=None):
def main(argv):
args = parser.parse_args(argv)
if args_postprocessor is not None:
args = args_postprocessor(args)
return args.func(args)
return subparser_betterhelp(parser, main_docstring, sub_docstrings)(main)(argv)