#!/usr/bin/env python3
from sys import argv
import os
##################################################
#  makeJava.py
#  Author: John M. Morrison.  Released without warrantee with a GPL v3 license.
#  8 Dec 2021:   upgrated to Python 3 and f-strings.
#  28 Aug 2023:  allow user to specify date; default is today.
#                add full documentation
#                add overwrite check
#  Date format must be entered as yyyymmdd.
#  usages:
#       python makedJava.py filename   (default date is today)
#       python makedJava.py filename yyyymmdd  (specify date)
#  usage note: if you are running on UNIX with execute permissions, you can
#              omit the "python" in the two commands above if this file is located
#              in a directory in your $PATH.
#  product:
#       a skeleton java file with a comment header, a default
#       constructor, a main maethod, and a
#       date stamp.
##################################################

if len(argv) == 3:  #user specified date supplied
    date_data = argv[2]
    year = date_data[:4]
    month = date_data[4:6]
    day = date_data[6:8]
    date = datetime.fromisoformat(f"{year}-{month}-{day}")
    date = date.date()
elif len(argv) == 2:
    date = datetime.date(datetime.now())  #default to today
else:
    print("Usage:  python makeThree.py yyyymmdd")
    print("Bailing.... try again.")
    quit()

root = argv[1]
if os.path.exists(root + "java"):
    reply = input("File exists; do you want to clobber it (y/n)? ")
    if reply.lower() != "y":
        print("Bailing.  I won't overwrite your existing file.")
        quit()

with open(root + ".java", "w") as fp:
    fp.write(f"""/**************************************************
*   Author: Morrison
*   Date:  {date}
**************************************************/
public class {root}
{{
    public {root}()
    {{
    }}
    
    public static void main(String[] args)
    {{
    }}
}}""")
