#!/usr/bin/env python3
from sys import argv
import os
from datetime import datetime
##################################################
#  makeFX.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:  add full documentation
#                use {{ and }} to simplify file ouput.
#  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 javaFX file with a comment header, a
#       constructor, init method, start method and stop method,
#       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]
with open(root + ".java", "w") as fp:
    fp.write(f"""/**************************************************
*   Author: Morrison
*   Date:  {date}
**************************************************/
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import javafx.scene.Scene;
public class {root} extends Application
{{
    public {root}()
    {{
    }}

    @Override
    public void init()
    {{
    }}

    @Override
    public void start(Stage primary)
    {{
        primary.show();
    }}

    @Override
    public void stop()
    {{
    }}
}} """)
