package kalang.shell;

import java.io.File;
import java.io.IOException;
import kalang.compiler.Configuration;
import kalang.lang.Script;
import kalang.tool.KalangShell;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;

/**
 *
 * @author Kason Yang
 */
public class Kalangsh extends ShellBase {

    private final static String SYNTAX = "kalangsh [options] FILE [options]";

    public static void main(String[] args) {
        new Kalangsh().run(args);
    }

    private void run(String[] args) {
        Options options = new Options();
        options.addOption("c", "code", true, "run code from code option");
        CommandLine cli = parseArgs(options, args);
        if (cli == null || cli.hasOption("help")) {
            printUsage(SYNTAX, options);
            return;
        }
        run(cli, options);
    }

    private void run(CommandLine cli, Options options) {
        Configuration config = this.createConfiguration(cli);
        ClassLoader classLoader = this.createClassLoader(cli);

        String[] args = cli.getArgs();
        KalangShell sh = new KalangShell(config, classLoader);
        try {
            Script script;
            String[] scriptArgs;
            if (cli.hasOption("c")) {
                scriptArgs = new String[0];
                script = sh.parseScript("Temp", cli.getOptionValue("c"), "Tmp.kl");
            } else {
                if (args.length == 0) {
                    printUsage(SYNTAX, options);
                }
                File file = new File(args[0]);
                scriptArgs = new String[args.length - 1];
                if (args.length > 1) {
                    System.arraycopy(args, 1, scriptArgs, 0, scriptArgs.length);
                }
                script = sh.parseScript(file);
            }
            script.run(scriptArgs);
        } catch (IOException ex) {
            ex.printStackTrace(System.err);
        }
    }

}

@@ -636,24 +636,92 @@
 e option%22);%0A
+        options.addOption(%22%22,%22check%22,false,%22don't run,just check%22);%0A
         Comm
@@ -1866,32 +1866,79 @@
 ;%0A            %7D%0A
+            if (!cli.hasOption(%22check%22)) %7B%0A    
             scri
@@ -1953,24 +1953,38 @@
 criptArgs);%0A
+            %7D%0A
         %7D ca

support --check option