package de.dhbwstuttgart.core;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.*;
public class ConsoleInterface {
	private static final String directory = System.getProperty("user.dir");

	public static void main(String[] args) throws IOException, ClassNotFoundException {
		List<File> input = new ArrayList<>();
		List<File> classpath = new ArrayList<>();
        String outputPath = null;
		Iterator<String> it = Arrays.asList(args).iterator();
        if(args.length == 0){
            System.out.println("No input files given. Get help with --help");
            System.exit(1);
        }else if(args.length == 1 && args[0].equals("--help")){
            System.out.println("Usage: javatx [OPTION]... [FILE]...\n" +
                    "\t-cp\tSet Classpath\n" +
                    "\t-d\tSet destination directory");
            System.exit(1);
        }
		while(it.hasNext()){
            String arg = it.next();
            if(arg.equals("-d")){
                outputPath = it.next();
            }else if(arg.startsWith("-d")) {
                outputPath = arg.substring(2);
            }else if(arg.equals("-cp") || arg.equals("-classpath")){
                String[] cps = it.next().split(":");
                for(String cp : cps){
                    classpath.add(new File(cp));
                }
            }else{
                input.add(new File(arg));
            }
        }
		JavaTXCompiler compiler = new JavaTXCompiler(input, classpath, outputPath != null ? new File(outputPath) : null);
		//compiler.typeInference();
		compiler.generateBytecode();
	}


}
