package kalang.lang;

import kalang.annotation.Nullable;

/**
 *
 * @author Kason Yang
 */
public abstract class Script {

    public final static int SUCCESS = 0;

    private String[] arguments = new String[0];

    protected abstract void execute() throws Throwable;

    public int run() throws Throwable {
        try{
            execute();
        }catch(Throwable e) {
            handleException(e);
        }
        return SUCCESS;
    }

    public int run(@Nullable String[] arguments) throws Throwable {
        if (arguments != null) {
            this.arguments = arguments;
        }
        return run();
    }
    
    protected String[] arguments(){
        return this.arguments;
    }
    
    protected void handleException(Throwable e) throws Throwable{
        throw e;
    }

}

@@ -697,32 +697,191 @@
 nts;%0A    %7D%0A    %0A
+    protected String argument(int index,@Nullable String defaultValue) %7B%0A        return arguments.length %3E index ? arguments%5Bindex%5D : defaultValue;%0A    %7D%0A    %0A
     protected vo

add argument method