#!python
"""
Script to concatenate the MS files from Linc for input to Rapthor
"""
import argparse
import glob
import os
import sys
from rapthor.scripts.concat_ms import concat_ms


def main(input_path, output_file):
    """
    Concatenate MS files from Linc for input to Rapthor

    Parameters
    ----------
    input_path : str
        Full path to the directory with the Linc MS files
    output_file : str
        Filename of output file
    """
    msfiles = []
    for pattern in ["*.ms", "*.MS"]:
        msfiles.extend(glob.glob(os.path.join(input_path, pattern)))
    return concat_ms(msfiles, output_file)


if __name__ == "__main__":
    descriptiontext = "Concatenate Linc MS files.\n"
    parser = argparse.ArgumentParser(
        description=descriptiontext, formatter_class=argparse.RawTextHelpFormatter
    )
    parser.add_argument(
        "input_path", help="Full path to the directory with the Linc MS files"
    )
    parser.add_argument("output_file", help="Output filename")

    args = parser.parse_args()
    sys.exit(main(args.input_path, args.output_file))
