import os
import sys
import shutil
import argparse

__PROJECT_ROOT__ = os.path.abspath(os.path.join(os.path.dirname(__file__),os.pardir))

def main(cli_args):
    
    parser = argparse.ArgumentParser(
        description = 'Copies junit file generated by tests')

    default_Workspace = './'
    parser.add_argument(
        '-src',
        type = str,
        default = os.path.join(__PROJECT_ROOT__, 'docs', 'pytest_out', 'junit.xml'),
        dest = 'src',
        help = f'Source junit file.',
        metavar = '',
    )
    parser.add_argument(
        '-dst',
        type = str,
        default = os.path.join(__PROJECT_ROOT__, 'pytest_out'),
        dest = 'dst',
        help = f'Target folder.',
        metavar = '',
    )
    parser.add_argument(
        '-tag',
        type = str,
        default = '',
        dest = 'tag',
        help = f'Unique tag for identification.',
        metavar = '',
    )

    args = parser.parse_args(cli_args)
    
    if not os.path.isdir(args.dst):
        os.makedirs(args.dst)
        
    if len(args.tag) > 0:
        tag = f'-{args.tag}'
    else:
        tag = ''
        
    dst = os.path.join(args.dst, f'junit{tag}.xml')
    
    shutil.copy(args.src, dst)
    
if __name__ == "__main__":
    main(sys.argv[1:])   
