def parse_query(query_to_parse):
    """
    Converts a comma or space-separated string of query terms into a list to use
    as filters.  The use of positional arguments on the CLI provides lists (which
    we join and resplit to avoid any formatting issues), while strings passed
    from pssh.py just get split since those should never come over as a list.
    """
    if isinstance(query_to_parse, list):
        _query = ','.join(query_to_parse)
    else:
        _query = query_to_parse.replace(' ',',')
    split_query = _query.split(',')

    ### Pick up passed --region query from pssh.py
    parsed_query = [x for x in split_query if not x.startswith('--region=')]
    region_query = [x for x in split_query if x.startswith('--region')]
    parsed_regions = ','.join([x.split('=')[1] for x in region_query])

    return parsed_query, parsed_regions