package com.github.aureliano.achmed;

import com.github.aureliano.achmed.exception.AchmedException;
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;
		}
		
		if ((args[0].equals("-h")) || (args[0].equals("--help")) || (args[0].equals("help"))) {
			this.printHelp();
		} else if ((args[0].equals("-v")) || (args[0].equals("--version")) || (args[0].equals("version"))) {
			this.printVersion();
		} else if (args[0].equals("burst")) {
			this.handleExecution(args);
		} else {
			this.printError(args);
			System.exit(1);
		}
		
		System.exit(0);
	}
	
	protected void handleExecution(String[] args) {
		if (args.length == 1) {
			this.prepareExecution(null);
		} else if (args.length != 2) {
			throw new AchmedException("Invalid arguments. You can pass just one file path after burst command.");
		} else {
			this.prepareExecution(args[1]);
		}
	}

	protected void prepareExecution(String path) {
		if (StringHelper.isEmpty(path)) {
			System.out.println(ApplicationHelper.error(new String[0]));
			System.exit(1);
		}
		
		ApplicationHelper.execute(path);
	}

	protected void printHelp() {
		System.out.println(ApplicationHelper.help());
	}
	
	protected void printVersion() {
		System.out.println(ApplicationHelper.version());
	}
	
	private void printError(String[] args) {
		System.out.println(ApplicationHelper.error(args));
	}
}
@@ -35,70 +35,8 @@
 d;%0A%0A
-import com.github.aureliano.achmed.exception.AchmedException;%0A
 impo
@@ -402,16 +402,34 @@
 %0A%09%09%7D%0A%09%09%0A
+%09%09int status = 0;%0A
 %09%09if ((a
@@ -505,32 +505,41 @@
 (%22help%22))) %7B%0A%09%09%09
+status = 
 this.printHelp()
@@ -642,24 +642,33 @@
 on%22))) %7B%0A%09%09%09
+status = 
 this.printVe
@@ -715,24 +715,33 @@
 rst%22)) %7B%0A%09%09%09
+status = 
 this.handleE
@@ -766,24 +766,33 @@
 %7D else %7B%0A%09%09%09
+status = 
 this.printEr
@@ -802,35 +802,16 @@
 (args);%0A
-%09%09%09System.exit(1);%0A
 %09%09%7D%0A%09%09%0A%09
@@ -823,17 +823,22 @@
 em.exit(
-0
+status
 );%0A%09%7D%0A%09%0A
@@ -848,20 +848,19 @@
 otected 
-void
+int
  handleE
@@ -910,24 +910,31 @@
  == 1) %7B%0A%09%09%09
+return 
 this.prepare
@@ -990,32 +990,25 @@
 %0A%09%09%09
-throw new AchmedExceptio
+System.err.printl
 n(%22I
@@ -1081,16 +1081,29 @@
 and.%22);%0A
+%09%09%09return 1;%0A
 %09%09%7D else
@@ -1104,24 +1104,31 @@
 %7D else %7B%0A%09%09%09
+return 
 this.prepare
@@ -1166,20 +1166,19 @@
 otected 
-void
+int
  prepare
@@ -1308,31 +1308,34 @@
 %0A%09%09%09
-System.exit(1);%0A%09%09%7D%0A%09%09%0A
+return 1;%0A%09%09%7D%0A%09%09%0A%09%09try %7B%0A%09
 %09%09Ap
@@ -1365,16 +1365,142 @@
 (path);%0A
+%09%09%09return 0;%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 2;%0A%09%09%7D%0A
 %09%7D%0A%0A%09pro
@@ -1502,28 +1502,27 @@
 %0A%09protected 
-void
+int
  printHelp()
@@ -1568,24 +1568,36 @@
 er.help());%0A
+%09%09return 0;%0A
 %09%7D%0A%09%0A%09protec
@@ -1600,20 +1600,19 @@
 otected 
-void
+int
  printVe
@@ -1672,16 +1672,28 @@
 ion());%0A
+%09%09return 0;%0A
 %09%7D%0A%09%0A%09pr
@@ -1698,20 +1698,19 @@
 private 
-void
+int
  printEr
@@ -1783,12 +1783,24 @@
 args));%0A
+%09%09return 1;%0A
 %09%7D%0A%7D

Configure status to return when application shuts down.