#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Command line program interface
"""

# Authors:
# * Aaron Dettmann

import argparse
import os

from aeroframe.stdfun.run import standard_run
from aeroframe.stdfun.init import setup_project
from aeroframe.stdfun.plot import plot
from aeroframe import __prog_name__

def cli():
    """
    Command line interface
    """

    # ===== Arguments =====
    parser = argparse.ArgumentParser(prog=f'{__prog_name__}')
    subparsers = parser.add_subparsers(help='execution modes', dest='exec_mode')

    # ----- Mode 'run' -----
    sub = subparsers.add_parser('run', help='run an analysis')
    sub.add_argument('--dest', help='{__prog_name__} directory', default=os.getcwd())

    group = sub.add_mutually_exclusive_group()
    group.add_argument('-c', '--clean', help='remove old project files', action='store_true')
    group.add_argument('--clean-only', help='clean and exit', action='store_true')

    group = sub.add_mutually_exclusive_group()
    group.add_argument('-v', '--verbose', action='store_true')
    group.add_argument('-d', '--debug', action='store_true')
    group.add_argument('-q', '--quiet', action='store_true')

    # ----- Mode 'init' -----
    sub = subparsers.add_parser('init', help='initialise a project')
    sub.add_argument('-f', '--force', help='overwrite existing files', action='store_true')
    sub.add_argument('--dest', help='destination directory', default=os.getcwd())

    # ----- Mode 'plot' -----
    sub = subparsers.add_parser('plot', help='plot data fields')
    sub.add_argument('files', nargs='+', help='data field files')
    sub.add_argument('-p', '--percent', help='show X percent of data', type=int, default=100)

    args = parser.parse_args()

    if args.exec_mode == 'run':
        standard_run(args)
    elif args.exec_mode == 'init':
        setup_project(args)
    elif args.exec_mode == 'plot':
        plot(args)
    else:
        parser.print_help()


if __name__ == '__main__':
    cli()
