@@ -3,39 +3,46 @@ package hmm;
3
3
import hmm .commands .* ;
4
4
import hmm .utils .Log ;
5
5
import hmm .utils .Shell ;
6
+ using Lambda ;
6
7
7
8
class Hmm {
8
- public static var commands (default , null ) : Map <String , ICommand >;
9
+ public static var commandMap (default , null ) : Map <String , ICommand >;
9
10
10
11
public static function main () {
11
12
var args = Sys .args ();
12
13
13
- commands = [
14
- " clean" => new CleanCommand (),
15
- " install" => new InstallCommand (),
16
- " update" => new UpdateCommand ()
14
+ var commands : Array <ICommand > = [
15
+ new SetupCommand (),
16
+ new CleanCommand (),
17
+ new InstallCommand (),
18
+ new UpdateCommand ()
17
19
];
18
20
19
- var command = " " ;
21
+ var commandType = " " ;
22
+
23
+ Shell .hmmDirectory = Sys .getCwd ();
20
24
21
25
if (args .length == 2 ) {
22
26
// When running via `haxelib run` the current working directory is added to the end of the args list.
23
27
// Also, Sys.getCwd() gets the location of the haxelib install not the actual working directory.
24
28
Shell .workingDirectory = args .pop ();
25
- command = args .pop ();
29
+ commandType = args .pop ();
26
30
} else if (args .length == 1 ) {
27
31
Shell .workingDirectory = Sys .getEnv (" PWD" );
28
- command = args .pop ();
32
+ commandType = args .pop ();
29
33
} else {
30
34
showUsage ();
31
35
}
32
36
33
- if (! commands .exists (command )) {
34
- Log .error (' Invalid command: $command ' );
37
+ var command = commands .find (function (command ) {
38
+ return command .type == commandType ;
39
+ });
40
+ if (command == null ) {
41
+ Log .error (' Invalid command: $commandType ' );
35
42
Sys .exit (1 );
36
43
}
37
44
38
- commands [ command ] .run ();
45
+ command .run ();
39
46
}
40
47
41
48
static function showUsage () {
0 commit comments