Browse Source

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.

(From OE-Core rev: 3ef5b518febd047bf90a0955fa2b9fb78ba6dde5)

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Aníbal Limón 8 năm trước cách đây
mục cha
commit
3aa299d51b
1 tập tin đã thay đổi với 7 bổ sung0 xóa
  1. 7 0
      scripts/lib/argparse_oe.py

+ 7 - 0
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