From 3ef5b518febd047bf90a0955fa2b9fb78ba6dde5 Mon Sep 17 00:00:00 2001 From: Aníbal Limón Date: Tue, 11 Jul 2017 09:16:28 -0700 Subject: argparse_oe: Add int_positive type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- scripts/lib/argparse_oe.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'scripts') 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 -- cgit 1.2.3-korg