Skip to content

Commit 7e40f7c

Browse files
committed
Refactor and add reinstall command
1 parent d8d0e2c commit 7e40f7c

31 files changed

+1049
-415
lines changed

.gitignore

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,9 @@
1-
# Logs
2-
logs
3-
*.log
4-
5-
# Runtime data
6-
pids
7-
*.pid
8-
*.seed
9-
10-
# Directory for instrumented libs generated by jscoverage/JSCover
11-
lib-cov
12-
13-
# Coverage directory used by tools like istanbul
14-
coverage
15-
16-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17-
.grunt
18-
19-
# node-waf configuration
20-
.lock-wscript
21-
22-
# Compiled binary addons (http://nodejs.org/api/addons.html)
23-
build/Release
24-
25-
# Dependency directory
26-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
1+
# Node
272
node_modules
283

4+
# Haxe
5+
.haxelib
6+
297
# Project files
8+
bin/
309
hmm.zip

build.hxml

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
-cp src
2+
-lib thx.core
3+
4+
--each
5+
26
-main hmm.Hmm
37
-neko run.n
8+
9+
--next
10+
11+
-lib utest
12+
-cp test
13+
-main TestAll
14+
-neko bin/test-all.n
15+
-cmd neko bin/test-all.n

haxelib.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"classPath": "src/",
99
"releasenote": "Add check command to check install status of libs",
1010
"contributors": ["andywhite37"],
11-
"dependencies": {}
11+
"dependencies": {
12+
"utest": "1.5.0",
13+
"thx.core": "0.42.1"
14+
}
1215
}

hmm.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"dependencies": [
3+
{
4+
"type": "haxelib",
5+
"name": "utest",
6+
"version": "1.5.0"
7+
},
8+
{
9+
"type": "haxelib",
10+
"name": "thx.core",
11+
"version": "0.42.1"
12+
}
13+
]
14+
}

run.n

276 KB
Binary file not shown.

src/hmm/Hmm.hx

+64-41
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,93 @@
11
package hmm;
22

3+
using Lambda;
4+
5+
using thx.Functions;
6+
37
import hmm.commands.*;
8+
import hmm.errors.*;
49
import hmm.utils.Log;
510
import hmm.utils.Shell;
6-
using Lambda;
711

812
class Hmm {
913
public static var commands(default, null) : Array<ICommand>;
1014

1115
public static function main() {
12-
commands = [
13-
new HelpCommand(),
14-
new VersionCommand(),
15-
new SetupCommand(),
16-
new InitCommand(),
17-
new FromHxmlCommand(),
18-
new ToHxmlCommand(),
19-
new InstallCommand(),
20-
new HaxelibCommand(),
21-
new GitCommand(),
22-
new HgCommand(),
23-
new UpdateCommand(),
24-
new RemoveCommand(),
25-
new CheckCommand(),
26-
new CleanCommand(),
27-
new HmmUpdateCommand(),
28-
new HmmRemoveCommand(),
29-
];
16+
try {
17+
commands = [
18+
new HelpCommand(),
19+
new VersionCommand(),
20+
new SetupCommand(),
21+
new InitCommand(),
22+
new FromHxmlCommand(),
23+
new ToHxmlCommand(),
24+
new InstallCommand(),
25+
new ReinstallCommand(),
26+
new HaxelibCommand(),
27+
new GitCommand(),
28+
new HgCommand(),
29+
new UpdateCommand(),
30+
new RemoveCommand(),
31+
new CheckCommand(),
32+
new CleanCommand(),
33+
new HmmUpdateCommand(),
34+
new HmmRemoveCommand(),
35+
];
3036

31-
var args = Sys.args();
37+
var args = Sys.args().copy();
3238

33-
Shell.init({
34-
hmmDirectory: Sys.getCwd(),
35-
workingDirectory: args.pop()
36-
});
39+
Shell.init({
40+
hmmDirectory: Sys.getCwd(),
41+
workingDirectory: args.pop()
42+
});
3743

38-
var commandType = args.shift();
44+
var commandType = args.shift();
45+
if (commandType == null) {
46+
throw new ValidationError('no command given', 1);
47+
}
3948

40-
var command = commands.find(function(command) {
41-
return command.type == commandType;
42-
});
49+
var command = commands.find(function(command) {
50+
return command.type == commandType;
51+
});
4352

44-
if (command == null) {
45-
Log.error('invalid command: $commandType');
46-
printUsageAndExit();
47-
Sys.exit(1);
48-
}
53+
if (command == null) {
54+
throw new ValidationError('unrecognized command: $commandType', 1);
55+
}
4956

50-
//Log.info("hmm");
51-
//Log.info('working directory: ${Shell.workingDirectory}');
52-
//Log.info('hmm directory: ${Shell.hmmDirectory}');
53-
//Log.info('command: $commandType');
57+
command.run(args);
58+
} catch (e : ValidationError) {
59+
die('Validation error: ${e.message}', e.statusCode);
60+
} catch (e : SystemError) {
61+
die('Execution error: ${e.message}', e.statusCode);
62+
} catch (e : Dynamic) {
63+
die('Unexpected error: $e', 1);
64+
}
65+
}
5466

55-
command.run(args);
67+
static function die(message : String, statusCode : Int) : Void {
68+
Log.error(message);
69+
Log.println('Use "hmm help" to see usage');
70+
Sys.exit(statusCode);
5671
}
5772

58-
public static function printUsageAndExit() {
73+
public static function printUsageAndExit(statusCode : Int) : Void {
5974
Log.println("Usage: hmm <command> [options]");
6075
Log.println("");
6176
Log.println("commands:");
6277
Log.println("");
63-
for (command in commands) {
78+
printUsagesAndExit(commands.map.fn(_.type), statusCode);
79+
}
80+
81+
public static function printUsagesAndExit(types : Array<String>, statusCode : Int) : Void {
82+
for (type in types) {
83+
var command = commands.find.fn(_.type == type);
84+
if (command == null) {
85+
throw new ValidationError('invalid command: $type', 1);
86+
}
6487
Log.println(' ${command.type} - ${command.getUsage()}');
6588
Log.println("");
6689
}
67-
Sys.exit(1);
90+
Sys.exit(statusCode);
6891
}
6992
}
7093

0 commit comments

Comments
 (0)