#!/usr/bin/env python
from pathlib import Path
import os
import argparse
import sys
from tabulate import tabulate

from eddy_squeeze.eddy_squeeze import eddy_squeeze_study


def parse_args(argv):
    '''Parse inputs coming from the terminal'''
    argparser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description='''\
        eddy_squeeze.
        Visualize extra information from FSL eddy outputs.
        ''')

    argparser.add_argument("--eddy_directories", "-ed",
                           type=str,
                           nargs='+',
                           default=[os.getcwd()],
                           help='Eddy output directories. Default = current '
                                'directory')

    argparser.add_argument("--eddy_prefix_pattern", "-ep",
                           type=str,
                           help='Prefix of eddy outputs to summarize. ' \
                                'Providing eddy_prefix will make eddy_dir '\
                                'ignored.')

    argparser.add_argument("--pnl", "-p",
                           action='store_true',
                           help='Option to use for PNL pipeline structure')

    argparser.add_argument("--out_dir", "-od",
                           type=str,
                           default='.',
                           help='Eddy summary output directory. Default = '
                                'PWD/eddy_summary')

    argparser.add_argument("--print_table", "-pt",
                           action='store_true',
                           help='Print Eddy output summary tables')

    argparser.add_argument("--save_html", "-sh",
                           action='store_true',
                           help='Save Eddy output information to html file')

    argparser.add_argument("--figures", "-f",
                           action='store_true',
                           help='Create figures to be included ' \
                                'in the html file')

    argparser.add_argument("--collect_figures", "-co",
                           action='store_true',
                           help='Collect all subject figures into the ' \
                                'output directory.')

    args = argparser.parse_args(argv)

    if len(sys.argv) == 1:
        argparser.print_help(sys.stderr)
        sys.exit(1)

    args.out_dir = Path(args.out_dir).absolute()

    return args


if __name__ == '__main__':
    args = parse_args(sys.argv[1:])
    eddy_squeeze_study(args)

