@@ -17,46 +17,54 @@ import haxe.io.Path;
1717import sys .FileSystem ;
1818import sys .io .File ;
1919
20+ typedef Command = {
21+ desc : String ,
22+ args : Array <String >,
23+ act : (Array <String >) -> Void ,
24+ example : String ,
25+ order : Int ,
26+ };
27+
2028/**
2129 The commands that can be used with this script.
2230**/
23- final commands = {
24- help : {
31+ final commands : Map < String , Command > = [
32+ " help" => {
2533 desc : " Shows this message" ,
2634 args : [],
2735 act : (args ) -> Sys .println (helpContent ()),
2836 example : " help" ,
2937 order : 0
3038 },
31- " new" : {
39+ " new" => {
3240 desc : " Create a new Reflaxe project" ,
3341 args : [],
3442 act : (args : Array <String >) -> createNewProject (args ),
3543 example : " new Rust rs" ,
3644 order : 1
3745 },
38- test : {
46+ " test" => {
3947 desc : " Test your target on .hxml project" ,
4048 args : [" hxml_path" ],
4149 act : (args : Array <String >) -> testProject (args ),
4250 example : " test test/Test.hxml" ,
4351 order : 2
4452 },
45- build : {
53+ " build" => {
4654 desc : " Build your project for distribution" ,
4755 args : [" build_folder" ],
4856 act : (args : Array <String >) -> buildProject (args ),
4957 example : " build _Build" ,
5058 order : 3
5159 },
52- parallel : {
60+ " parallel" => {
5361 desc : " Run multiple .hxml files in parallel" ,
5462 args : [" hxml_path1" , " hxml_path2" , " ..." ],
5563 act : (args : Array <String >) -> parallel (args ),
5664 example : " parallel multiprocess/Compile1.hxml multiprocess/Compile2.hxml" ,
5765 order : 4
5866 }
59- }
67+ ];
6068
6169/**
6270 The directory this command was run in.
@@ -70,11 +78,11 @@ function main() {
7078 final args = Sys .args ();
7179 commandRunDir = args .splice (args .length - 1 , 1 )[0 ];
7280 final mainCommand = args .length < 1 ? " help" : args [0 ];
73- if (Reflect . hasField ( commands , mainCommand )) {
74- Reflect . callMethod ( commands , Reflect . getProperty ( commands , mainCommand ).act , [ args .slice (1 )] );
81+ if (commands . exists ( mainCommand )) {
82+ commands . get ( mainCommand )? .act ( args .slice (1 ));
7583 } else {
7684 printlnRed (" Could not find command: " + mainCommand + " \n " );
77- commands .help .act (args );
85+ commands .get ( " help" ) ? .act (args );
7886 }
7987}
8088
@@ -107,17 +115,18 @@ function printlnGray(msg: String) { Sys.println('\033[1;30m${msg}\033[0m'); }
107115function helpContent (): String {
108116 var maxFieldSize = - 1 ;
109117
110- final commandNames = Reflect . fields ( commands ) ;
118+ final commandNames = [ for ( k in commands . keys ()) k ] ;
111119 commandNames .sort ((a , b ) -> {
112- final i = Reflect . getProperty ( commands , a )?. order ?? 9999 ;
113- final j = Reflect . getProperty ( commands , b )?. order ?? 9999 ;
120+ final i = commands . get ( a )?. order ?? - 9999 ;
121+ final j = commands . get ( b )?. order ?? - 9999 ;
114122 return i - j ;
115123 });
116124
117125 // Convert "commands" into an array
118126 final data = [];
119127 for (field in commandNames ) {
120- final c = Reflect .getProperty (commands , field );
128+ final c = commands .get (field );
129+ if (c == null ) continue ;
121130 final args = c .args .map (c -> " <" + c + " >" ).join (" " );
122131 final helpName = field + (args .length > 0 ? (" " + args ) : " " );
123132
0 commit comments