summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2016-05-13 17:30:08 (GMT)
committerAssaf Gordon <assafgordon@gmail.com>2016-05-13 17:30:08 (GMT)
commitd905ea6def122d4c5fe0be4ef58c066ee36a8882 (patch)
treebe0d073c79261dba9fc7706ec2b3cd4a1ca764d4
parent893e03e7d31d412af3d9975a91e42924b8a42618 (diff)
downloadcode-snippets-d905ea6def122d4c5fe0be4ef58c066ee36a8882.zip
code-snippets-d905ea6def122d4c5fe0be4ef58c066ee36a8882.tar.gz
code-snippets-d905ea6def122d4c5fe0be4ef58c066ee36a8882.tar.bz2
skeleton.py: add integer parameter validation example
-rwxr-xr-xskeleton.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/skeleton.py b/skeleton.py
index b4220c7..49294e0 100755
--- a/skeleton.py
+++ b/skeleton.py
@@ -35,11 +35,18 @@ Example:
help="disable feature")
parser.set_defaults(feature=True)
+ # A numeric optional parameter, not required (could be None)
+ parser.add_argument("-L", "--limit", metavar="N", type=int,
+ help="Limit to N events (defaul: no limit)")
# Positional parameter
parser.add_argument('filename', metavar='FILE', help='file to process');
args = parser.parse_args()
+ # Ensure optional numeric param is either undefined, or above 0
+ if (args.limit is not None) and args.limit<1:
+ sys.exit("invalid limit (--limit %d)" % args.limit)
+
return args