From 593dfe5cb0be739ae6767926635314efec6f5ac7 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 30 Dec 2020 12:31:21 -0800 Subject: [PATCH] Add optional args_postprocessor. --- voussoirkit/betterhelp.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/voussoirkit/betterhelp.py b/voussoirkit/betterhelp.py index a49aec7..43c92da 100644 --- a/voussoirkit/betterhelp.py +++ b/voussoirkit/betterhelp.py @@ -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)