<commit_before>//
// Flambe - Rapid game development
// https://github.com/aduros/flambe/blob/master/LICENSE.txt

import sys.FileSystem;
import sys.io.File;

import haxe.Template;

using StringTools;

typedef Command = {
    var name :String;
    var handler :Void -> Void;
    var description :String;
};

class FlambeMain
{
    public function new (libDir :String, args :Array<String>)
    {
        _libDir = libDir;
        _args = args;
        _commands = [];

        addCommand("new", create, "Create a new project template");
        addCommand("setup", setup, "Setup Flambe");
        addCommand("help", help, "Print this help message");
    }

    public function run ()
    {
        if (_args.length > 0) {
            var cmd = _args[0];
            for (command in _commands) {
                if (command.name == cmd) {
                    Reflect.callMethod(this, command.handler, []);
                    return;
                }
            }
            Sys.println("Unknown command, \"" + cmd + "\"");
        }

        help();
    }

    public function setup ()
    {
        if (Sys.systemName() == "Windows") {
            var haxeDir = Sys.getEnv("HAXEPATH");
            if (haxeDir == null) {
                Sys.println("%HAXEPATH% environment variable not set, " +
                    "did you install Haxe properly?");
                Sys.exit(1);
            }
            File.copy(_libDir + "/bin/flambe-waf", haxeDir + "/flambe-waf.py");
            File.copy(_libDir + "/bin/flambe-waf.bat", haxeDir + "/flambe-waf.bat");

        } else {
            var dest = "/usr/bin/flambe-waf";
            try {
                File.copy(_libDir + "/bin/flambe-waf", dest);
            } catch (e :Dynamic) {
                Sys.println("Couldn't create " + dest + ", did you sudo?");
            }
        }
    }

    public function create ()
    {
        var name;
        do {
            name = read("Project identifier, one word please");
        } while (!~/^[a-z0-9]+$/i.match(name));

        var capitalName = name.charAt(0).toUpperCase() + name.substr(1);

        Sys.println("");
        Sys.println("-- Press enter to use the defaults --");

        var outputDir = read("Project directory", _cwd + name);

        var mainClassFull;
        do {
            mainClassFull = read("Main class, including package", capitalName + "Main");
        } while(!~/^([a-z][a-z0-9]*\.)*[A-Z][A-Za-z0-9]*/.match(mainClassFull));

        var idx = mainClassFull.lastIndexOf(".");
        var hasPackage = (idx >= 0);
        var mainClass = hasPackage ? mainClassFull.substr(idx+1) : mainClassFull;
        var mainClassPackage = hasPackage ? mainClassFull.substr(0, idx) : "";

        FileSystem.createDirectory(outputDir);
        FileSystem.createDirectory(outputDir + "/etc");
        FileSystem.createDirectory(outputDir + "/assets");
        FileSystem.createDirectory(outputDir + "/assets/bootstrap");

        var srcDir = outputDir;
        for (dir in ["src"].concat(hasPackage ? mainClassPackage.split(".") : [])) {
            srcDir += "/" + dir;
            FileSystem.createDirectory(srcDir);
        }

        var templateDir = _libDir + "/template";
        var ctx = {
            name: name,
            capitalName: capitalName,
            mainClassFull: mainClassFull,<commit_msg>First CI bug found :)<commit_after>//
// Flambe - Rapid game development
// https://github.com/aduros/flambe/blob/master/LICENSE.txt

import sys.FileSystem;
import sys.io.File;

import haxe.Template;

using StringTools;

typedef Command = {
    var name :String;
    var handler :Void -> Void;
    var description :String;
};

class FlambeMain
{
    public function new (libDir :String, args :Array<String>)
    {
        _libDir = libDir;
        _args = args;
        _commands = [];

        addCommand("new", create, "Create a new project template");
        addCommand("setup", setup, "Setup Flambe");
        addCommand("help", help, "Print this help message");
    }

    public function run ()
    {
        if (_args.length > 0) {
            var cmd = _args[0];
            for (command in _commands) {
                if (command.name == cmd) {
                    Reflect.callMethod(this, command.handler, []);
                    return;
                }
            }
            Sys.println("Unknown command, \"" + cmd + "\"");
        }

        help();
    }

    public function setup ()
    {
        if (Sys.systemName() == "Windows") {
            var haxeDir = Sys.getEnv("HAXEPATH");
            if (haxeDir == null) {
                Sys.println("%HAXEPATH% environment variable not set, " +
                    "did you install Haxe properly?");
                Sys.exit(1);
            }
            File.copy(_libDir + "/bin/flambe-waf", haxeDir + "/flambe-waf.py");
            File.copy(_libDir + "/bin/flambe-waf.bat", haxeDir + "/flambe-waf.bat");

        } else {
            var dest = "/usr/bin/flambe-waf";
            try {
                File.copy(_libDir + "/bin/flambe-waf", dest);
            } catch (e :Dynamic) {
                Sys.println("Couldn't create " + dest + ", did you sudo?");
            }
        }
    }

    public function create ()
    {
        var name;
        do {
            name = read("Project identifier, one word please");
        } while (!~/^[a-z0-9]+$/i.match(name));

        var capitalName = name.charAt(0).toUpperCase() + name.substr(1);

        Sys.println("");
        Sys.println("-- Press enter to use the defaults --");

        var outputDir = read("Project directory", Sys.getCwd() + name);

        var mainClassFull;
        do {
            mainClassFull = read("Main class, including package", capitalName + "Main");
        } while(!~/^([a-z][a-z0-9]*\.)*[A-Z][A-Za-z0-9]*/.match(mainClassFull));

        var idx = mainClassFull.lastIndexOf(".");
        var hasPackage = (idx >= 0);
        var mainClass = hasPackage ? mainClassFull.substr(idx+1) : mainClassFull;
        var mainClassPackage = hasPackage ? mainClassFull.substr(0, idx) : "";

        FileSystem.createDirectory(outputDir);
        FileSystem.createDirectory(outputDir + "/etc");
        FileSystem.createDirectory(outputDir + "/assets");
        FileSystem.createDirectory(outputDir + "/assets/bootstrap");

        var srcDir = outputDir;
        for (dir in ["src"].concat(hasPackage ? mainClassPackage.split(".") : [])) {
            srcDir += "/" + dir;
            FileSystem.createDirectory(srcDir);
        }

        var templateDir = _libDir + "/template";
        var ctx = {
            name: name,
            capitalName: capitalName,
            mainClassFull: mainClassFull,
{'fraction_non_alphanumeric': 0.1445008965929468, 'fraction_numerical': 0.0041841004184100415, 'mean_word_length': 1.8602564102564103, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686384', 'n_tokens_mistral': 2039, 'n_tokens_neox': 1949, 'n_words': 439}