From: Aníbal Limón Date: Tue, 11 Jul 2017 16:16:28 +0000 (-0700) Subject: argparse_oe: Add int_positive type X-Git-Tag: uninative-1.7~123 X-Git-Url: https://code.ossystems.io/gitweb?a=commitdiff_plain;h=3ef5b518febd047bf90a0955fa2b9fb78ba6dde5;p=openembedded-core.git argparse_oe: Add int_positive type Sometimes only expect positive values from cmdline so it's better to filter at parsing cmdline step instead of validate later. Signed-off-by: Aníbal Limón --- diff --git a/scripts/lib/argparse_oe.py b/scripts/lib/argparse_oe.py index bf6eb17197..9bdfc1ceca 100644 --- a/scripts/lib/argparse_oe.py +++ b/scripts/lib/argparse_oe.py @@ -167,3 +167,10 @@ class OeHelpFormatter(argparse.HelpFormatter): return '\n'.join(lines) else: return super(OeHelpFormatter, self)._format_action(action) + +def int_positive(value): + ivalue = int(value) + if ivalue <= 0: + raise argparse.ArgumentTypeError( + "%s is not a positive int value" % value) + return ivalue