@classmethod
    def _parse_option(cls, token):
        """
        Parse an option expression.

        :param token: The option expression
        :type token: str

        :rtype: InputOption
        """
        description = None
        validator = None

        if ' : ' in token:
            token, description = tuple(token.split(' : ', 2))

            token = token.strip()

            description = description.strip()

        # Checking validator:
        matches = re.match('(.*)\((.*?)\)', token)
        if matches:
            token = matches.group(1).strip()
            validator = matches.group(2).strip()

        shortcut = None

        matches = re.split('\s*\|\s*', token, 2)

        if len(matches) > 1:
            shortcut = matches[0].lstrip('-')
            token = matches[1]

        default = None
        mode = InputOption.VALUE_NONE

        if token.endswith('=*'):
            mode = InputOption.VALUE_REQUIRED | InputOption.VALUE_IS_LIST
            token = token.rstrip('=*')
        elif token.endswith('=?*'):
            mode = InputOption.VALUE_OPTIONAL | InputOption.VALUE_IS_LIST
            token = token.rstrip('=?*')
        elif token.endswith("=?"):
            mode = InputOption.VALUE_OPTIONAL
            token = token.rstrip('=?')
        elif token.endswith('='):
            mode = InputOption.VALUE_REQUIRED
            token = token.rstrip('=')

        matches = re.match('(.+)(\=[\?\*]*)(.+)', token)
        if matches:
            token = matches.group(1)
            operator = matches.group(2)
            default = matches.group(3)

            if operator == '=*':
                mode = InputOption.VALUE_REQUIRED | InputOption.VALUE_IS_LIST
            elif operator == '=?*':
                mode = InputOption.VALUE_OPTIONAL | InputOption.VALUE_IS_LIST
            elif operator == '=?':
                mode = InputOption.VALUE_OPTIONAL
            elif operator == '=':
                mode = InputOption.VALUE_REQUIRED

        return InputOption(token, shortcut, mode, description, default,
                           validator=validator)
dataset/ETHPy150Open sdispater/cleo/cleo/parser.py/Parser._parse_option/original