aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/bin/utils/cmd_line.py
blob: 02c596c7b1518e4f422ec34efdb53f7d6ece346d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Copyright 2016 (c) Egor Tensin <Egor.Tensin@gmail.com>
# This file is part of the "Simple image filters" project.
# For details, see https://github.com/egor-tensin/filters.
# Distributed under the MIT License.

import argparse

def parse_non_negative_integer(s):
    try:
        n = int(s)
    except ValueError:
        raise argparse.ArgumentTypeError('must be a non-negative integer: ' + s)
    if n < 0:
        raise argparse.ArgumentTypeError('must be a non-negative integer: ' + s)
    return n