#!/usr/bin/python
"""
Export neuroimaging results created with FSL feat following NIDM-Results
specification. The path to feat directory must be passed as first argument.

@author: Camille Maumet <c.m.j.maumet@warwick.ac.uk>
@copyright: University of Warwick 2013-2014
"""


from nidmfsl.fsl_exporter.fsl_exporter import FSLtoNIDMExporter
from nidmfsl import __version__
import argparse

if __name__ == "__main__":
    # Arguments and description
    parser = argparse.ArgumentParser(
        description='NIDM-Results exporter for FSL Feat.')
    parser.add_argument('feat_dir', help='Path to feat directory.')
    parser.add_argument(
        '-g', '--group', nargs=2, action='append',
        default=None,
        metavar=('GROUP_NAME', 'NUM_SUBJECTS'),
        help='Group label followed by number of subjects')
    parser.add_argument(
        "-o", "--output_name",
        help='Name of the output. A \".nidm.zip\" or \".nidm\" (when -d is use\
d) suffix will be appended.')
    parser.add_argument(
        "-d", "--directory-output",
        help='Produces a .nidm directory rather than a .nidm.zip file.',
        action='store_true')
    parser.add_argument(
        "-n", "--nidm_version",
        help='NIDM-Results version to use (default: latest).',
        default="1.3.0")
    parser.add_argument(
        '--version', action='version',
        version='{version}'.format(version=__version__))
    args = parser.parse_args()

    # Parse feat dir and export to NIDM
    fslnidm = FSLtoNIDMExporter(
        out_dirname=args.output_name, zipped=(not args.directory_output),
        version=args.nidm_version, feat_dir=args.feat_dir, groups=args.group)
    fslnidm.parse()
    output_path = fslnidm.export()

    print('NIDM export available at '+output_path)
