#!/usr/bin/python
# Author: Theodore Zacharia
# V0.1: 03/08/2021 - Initial Release
#
# This script provides a template to start all other scripts with
# supports arguments being passed
#
# The canonical solution in the standard library is argparse
# which is this version, there is also a getopt solution in another script
# 
#
import argparse
import time
from datetime import datetime

# ****************************************************
# Globals
trace = 0

# ****************************************************
# Functions

def usage():
	print ('[-h] [-t|-T] [-a argvalue] [-b myarg1value|--myarg1 myarg1value] [-c myarg2value|--myarg2 myarg2value] positional_params')
	print ("where:")
	print (" -h displays this help message")
	print (" -t is trace mode, -T is more trace info")
	print (" -a is an arg value")
	print ("Examples:")
	print ("python ", sys.argv[0] , "-t -a avalue")


def getargs():
    global trace

    parser = argparse.ArgumentParser(description="A template script with argparse")
    parser.add_argument("-a", help="set argvalue")
    parser.add_argument("-t", "--trace", action="store_true", help="set trace mode")
    parser.add_argument("-T", "--TRACE", action="store_true", help="set louder TRACE mode")
    parser.add_argument("-b", "--myarg1", help="set myarg1 value")
    parser.add_argument("-c", "--myarg2", help="set myarg2 value")
    parser.add_argument("--ignore-existing", action="store_true", help="skip stuff that exist")
    parser.add_argument("--exclude", help="stuff to exclude")
    parser.add_argument("positional1", help="positional1 param")
    parser.add_argument("positional2", help="positional2 param")
    args = parser.parse_args()
    config = vars(args)
    print(config)

    print ("args=", args)

    if args.trace:
        print ("trace is on")
        trace = 1
        
    if args.TRACE:
        print ("TRACE is on")
        trace = 2

    if args.a:
        print ("-a value is",args.a)

    if args.myarg1:
        print ("-b/--myarg1 value is",args.myarg1)

    if args.myarg2:
        print ("-c/--myarg2 value is",args.myarg2)

    if len( vars(args) ) > 0:
        if trace > 0:
            if trace > 1:
                current_time = datetime.now()
            else:
                current_time = time.ctime()
            print ("Starting at", current_time)
            print ("args processed")
            print (args)


# ****************************************************
# Mainline

getargs()