def validate_int_arg(args, name, low=None, high=None):
    """Validate an integer command-line argument."""
    value = args.get(name) if isinstance(args, dict) else args
    if not value:
        return 0
    try:
        intval = int(value)
    except ValueError:
        raise ValueError('invalid integer for {0}: {1}'.format(name, value))
    if low is not None and intval < low:
        raise ValueError('invalid value for {0}: minimum is {1}, got {2}'.
            format(name, low, value))
    if high is not None and intval > high:
        raise ValueError('invalid value for {0}: maximum is {1}, got {2}'.
            format(name, high, value))
    return intval
