def circuit_command(api, command, name=None, **selection):
    """Run mobilities circuit commands.

    :param command: in ['list', 'get']
    :param name: circuit name
    :param **selections: selections by circuit site and type

    """
    assert command in ('list', 'get')
    if 'type' in selection:
        assert selection['type'] in ('predefined', 'userdefined')
    if command == 'list':
        result = api.get_circuits(**selection)
    elif command == 'get':
        result = api.get_circuit(name)
    else:
        raise ValueError('Unknown command %r' % command)
    return result
