forked from HeapsIO/heaps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun.hx
More file actions
72 lines (60 loc) · 2.06 KB
/
Run.hx
File metadata and controls
72 lines (60 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import haxe.io.Path;
import sys.FileSystem;
private typedef RunInvocation = {
var args:Array<String>;
var callerCwd:String;
var libraryRoot:String;
}
class Run {
static function main():Void {
var invocation = parseInvocation(Sys.args());
if( invocation.args.length == 0 ) {
printUsage();
return;
}
var command = invocation.args[0];
switch( command ) {
case "preview":
if( invocation.args.length < 2 ) {
throw "Usage: cgdheaps preview <module>";
}
cgd.cli.preview.PreviewMain.run(invocation.args[1], invocation.callerCwd, invocation.libraryRoot);
default:
throw 'Unknown cgdheaps command "${command}". Supported commands: preview';
}
}
static function parseInvocation(rawArgs:Array<String>):RunInvocation {
var args = rawArgs.copy();
var libraryRoot = normalizeDirectory(Sys.getCwd());
var callerCwd = libraryRoot;
if( Sys.getEnv("CGDHEAPS_RUN") == "1" && args.length > 0 ) {
callerCwd = normalizeDirectory(args.pop());
}
return {
args: args,
callerCwd: callerCwd,
libraryRoot: libraryRoot
};
}
static function normalizeDirectory(path:String):String {
var full = path;
if( !Path.isAbsolute(full) ) {
full = FileSystem.fullPath(full);
}
full = full.split("\\").join("/");
while( full.length > 1 && StringTools.endsWith(full, "/") ) {
full = full.substr(0, full.length - 1);
}
if( !FileSystem.exists(full) || !FileSystem.isDirectory(full) ) {
throw 'Directory does not exist: ${path}';
}
return full;
}
static function printUsage():Void {
Sys.println("cgdheaps command line tools");
Sys.println("");
Sys.println("Usage:");
Sys.println(" cgdheaps preview <module>");
Sys.println(" haxe --run Run.hx preview <module>");
}
}