#!/usr/bin/env python3
# vim:fileencoding=utf-8
"""_____________________________________________________________________

:PROJECT: ChemDataReader

* Main module command line interface *

:details:  Main module command line interface. 
           !!! Warning: it should have a diffent name than the package name.

.. note:: -
.. todo:: - 
________________________________________________________________________
"""

"""Main module implementation. !!! Warning: it should have a diffent name than the package name. """
"""Console script for chemdatareader."""

import logging
import argparse
import sys
import asyncio
from chemdatareader.chemdatareader_logger import get_logger
from chemdatareader import __version__

from chemdatareader.chemdatareader_impl import ChemDatReader

logging.basicConfig(level=logging.DEBUG)    

def parse_command_line():
    """ Looking for command line arguments"""

    description = "chemdatareader"
    parser = argparse.ArgumentParser(description=description)

    parser.add_argument("_", nargs="*")

    parser.add_argument(
        "-f", "--csv-filename", action="store", help="filename of the csv file"
    )

    parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__)

    # add more arguments here

    return parser.parse_args()

async def main():
    """Console script for chemdatareader."""
        # or use logging.INFO (=20) or logging.ERROR (=30) for less output
    
    logger = get_logger(__name__)
    
    args = parse_command_line()
        
    if len(sys.argv) <= 2:
        logging.debug("no arguments provided !")

    #print("Arguments: " + str(args._))   
    
    cdr = ChemDatReader()
    if args.csv_filename:
        logger.debug(f"csv_filename : {args.csv_filename}")
        await cdr.read_cas_csv(args.csv_filename)
    
    return 0

def main_async():
    asyncio.run(main())

if __name__ == "__main__":
     sys.exit(main_async())  # pragma: no cover
