import re


def _get_cmds_inputs(ctx, ci):
    """Parse and return commands and TOSCA inputs."""
    cmds = []
    inputs = {}
    pipe = False
    i = 0
    while i < len(ci):
        if ci[i].startswith('--'):
            # Parse TOSCA inputs in the two possible format:
            # --key value or --key=value
            if '=' in ci[i]:
                k, v = ci[i].split('=')
                inputs[k[2:]] = v
            elif i < len(ci) - 1:
                inputs[ci[i][2:]] = ci[i + 1]
                i += 1
            else:
                ctx.fail('missing the TOSCA inputs value.')
        if ci[i] == '-':
            pipe = True
        else:
            # Check that the format of the operation si correct
            if re.match('.*:.*\..*', ci[i]) is None:
                ctx.fail('"{}" not valid format. Should be COMPONENT:INTERFACE.OPERATION.'
                         ''.format(ci[i]))
            
            cmds.append(ci[i])
        i += 1
    return pipe, cmds, inputs