package com.github.aureliano.achmed;

import com.github.aureliano.achmed.helper.ApplicationHelper;
import com.github.aureliano.achmed.helper.StringHelper;

public class Application {

	public Application() {
		super();
	}
	
	public static void main(String[] args) {
		new Application().startUp(args);
	}
	
	public void startUp(String[] args) {
		if (args.length == 0) {
			this.printHelp();
			return;
		}
		
		int status = 0;
		if ((args[0].equals("-h")) || (args[0].equals("--help")) || (args[0].equals("help"))) {
			status = this.printHelp();
		} else if ((args[0].equals("-v")) || (args[0].equals("--version")) || (args[0].equals("version"))) {
			status = this.printVersion();
		} else if (args[0].equals("burst")) {
			status = this.handleExecution(args);
		} else {
			status = this.printError(args);
		}
		
		System.exit(status);
	}
	
	protected int handleExecution(String[] args) {
		if (args.length == 1) {
			return this.prepareExecution(null);
		} else if (args.length != 2) {
			System.err.println("Invalid arguments. You can pass just one file path after burst command.");
			return 1;
		} else {
			return this.prepareExecution(args[1]);
		}
	}

	protected int prepareExecution(String path) {
		if (StringHelper.isEmpty(path)) {
			System.out.println(ApplicationHelper.error(new String[0]));
			return 1;
		}
		
		try {
			ApplicationHelper.execute(path);
			return 0;
		} catch (Exception ex) {
			System.err.println(ex.getMessage());
			ex.printStackTrace();
			
			return 2;
		}
	}

	protected int printHelp() {
		System.out.println(ApplicationHelper.help());
		return 0;
	}
	
	protected int printVersion() {
		System.out.println(ApplicationHelper.version());
		return 0;
	}
	
	private int printError(String[] args) {
		System.out.println(ApplicationHelper.error(args));
		return 1;
	}
}
@@ -31,16 +31,78 @@
 chmed;%0A%0A
+import com.github.aureliano.achmed.exception.AchmedException;%0A
 import c
@@ -209,16 +209,69 @@
 gHelper;
+%0Aimport com.github.aureliano.achmed.types.StatusCode;
 %0A%0Apublic
@@ -519,19 +519,26 @@
 %09%7D%0A%09%09%0A%09%09
-int
+StatusCode
  status 
@@ -539,17 +539,20 @@
 tatus = 
-0
+null
 ;%0A%09%09if (
@@ -954,16 +954,26 @@
 t(status
+.getCode()
 );%0A%09%7D%0A%09%0A
@@ -983,19 +983,26 @@
 otected 
-int
+StatusCode
  handleE
@@ -1229,25 +1229,55 @@
 ;%0A%09%09%09return 
-1
+StatusCode.CLI_PARAMETERS_ERROR
 ;%0A%09%09%7D else %7B
@@ -1338,19 +1338,26 @@
 otected 
-int
+StatusCode
  prepare
@@ -1490,17 +1490,47 @@
 %09return 
-1
+StatusCode.CLI_PARAMETERS_ERROR
 ;%0A%09%09%7D%0A%09%09
@@ -1584,17 +1584,34 @@
 %09return 
-0
+StatusCode.SUCCESS
 ;%0A%09%09%7D ca
@@ -1615,16 +1615,22 @@
  catch (
+Achmed
 Exceptio
@@ -1716,17 +1716,169 @@
 %09return 
-2
+ex.getCode();%0A%09%09%7D catch (Exception ex) %7B%0A%09%09%09System.err.println(ex.getMessage());%0A%09%09%09ex.printStackTrace();%0A%09%09%09%0A%09%09%09return StatusCode.COMMON_EXECUTION_ERROR
 ;%0A%09%09%7D%0A%09%7D
@@ -1886,27 +1886,34 @@
 %0A%09protected 
-int
+StatusCode
  printHelp()
@@ -1964,33 +1964,50 @@
 lp());%0A%09%09return 
-0
+StatusCode.SUCCESS
 ;%0A%09%7D%0A%09%0A%09protecte
@@ -2008,19 +2008,26 @@
 otected 
-int
+StatusCode
  printVe
@@ -2096,17 +2096,34 @@
 %09return 
-0
+StatusCode.SUCCESS
 ;%0A%09%7D%0A%09%0A%09
@@ -2130,19 +2130,26 @@
 private 
-int
+StatusCode
  printEr
@@ -2231,15 +2231,45 @@
 %09return 
-1
+StatusCode.CLI_PARAMETERS_ERROR
 ;%0A%09%7D%0A%7D

Configure status code to send when program shuts down.