from typing import List
import re


def _parse_layers(s: str) -> List[int]:
    """Parse the commandline argument (csv) for the layers to use (must be clamped)"""
    range_re = re.compile(r'^(\d+)-(\d+)$')
    m = range_re.match(s)
    if m:
        layers = list(range(int(m.group(1)), int(m.group(2)) + 1))
    else:
        layers = [int(x) for x in s.split(',')]
    layers = [max(min(x, 5), 0) for x in layers]  # Clamp values between 0 and 5
    layers = list(set(layers))  # Remove duplicates due to either user input or clamping above
    return layers