@@ -21,13 +21,22 @@ typedef ShellOptions = {
21
21
throwError : Bool
22
22
};
23
23
24
+ typedef ShellInitOptions = {
25
+ hmmDirectory : String ,
26
+ workingDirectory : String ,
27
+ isWin : Bool
28
+ }
29
+
24
30
class Shell {
25
31
public static var hmmDirectory (default , default ) : String ;
26
32
public static var workingDirectory (default , default ) : String ;
33
+ public static var isWin (default , default ) : Bool ;
27
34
28
- public static function init (options : { hmmDirectory : String , workingDirectory : String } ) : Void {
35
+ public static function init (options : ShellInitOptions ) : Void {
29
36
hmmDirectory = options .hmmDirectory ;
30
37
workingDirectory = options .workingDirectory ;
38
+ isWin = options .isWin ;
39
+ AnsiColors .disabled = isWin ;
31
40
setCwd (workingDirectory , { log : false });
32
41
}
33
42
@@ -105,21 +114,22 @@ class Shell {
105
114
var outputString = commandResult .stdout ;
106
115
var outputLines = outputString .split (" \n " );
107
116
var result = { statusCode : commandResult .statusCode , isInstalled : false , path : null , libraryName : null , version : null };
108
- for (outputLine in outputLines ) {
109
- if (~/ is not installed/ i .match (outputLine )) {
117
+ var notInstalledRegex = ~/ is not installed/ i ;
118
+ var versionRegex = ~/ ^ \s * -D\s * (. * )=(. * )\s * $ / ;
119
+ var pathRegex = ~/ ^ (\/ | [A-Z ] :)/ ;
120
+ for (line in outputLines ) {
121
+ var outputLine = line .trim ();
122
+ if (notInstalledRegex .match (outputLine )) {
110
123
result .isInstalled = false ;
111
124
return result ;
112
125
}
113
126
result .isInstalled = true ;
114
- if (outputLine . trim (). startsWith ( " / " ) && result .path == null ) {
127
+ if (result .path == null && pathRegex . match ( outputLine ) ) {
115
128
// capture the path to the library if it has not yet been captured
116
129
result .path = outputLine ;
117
- } else if (outputLine .trim ().startsWith (" -D" ) && result .libraryName == null && result .version == null ) {
118
- var regex = ~/ ^ \s * -D\s * (. * )=(. * )\s * $ / ;
119
- if (regex .match (outputLine )) {
120
- result .libraryName = regex .matched (1 );
121
- result .version = regex .matched (2 );
122
- }
130
+ } else if (result .libraryName == null && result .version == null && versionRegex .match (outputLine )) {
131
+ result .libraryName = versionRegex .matched (1 );
132
+ result .version = versionRegex .matched (2 );
123
133
}
124
134
if (result .isInstalled && result .path != null && result .libraryName != null && result .version != null ) {
125
135
return result ;
@@ -256,10 +266,15 @@ class Shell {
256
266
}
257
267
258
268
public static function createHmmLink (realPath : String , linkPath : String ) : Void {
259
- // TODO: windows support?
260
- runCommand (" chmod" , [" +x" , realPath ], { log : true , throwError : true });
261
- runCommand (" sudo" , [" rm" , linkPath ], { log : true , throwError : false });
262
- runCommand (" sudo" , [" ln" , " -s" , realPath , linkPath ], { log : true , throwError : true });
269
+ if (isWin ) {
270
+ var safeRealPath = realPath .replace (" /" , " \\ " );
271
+ var safeLinkPath = linkPath .replace (" /" , " \\ " );
272
+ runCommand (" copy" , [" /Y" , safeRealPath , safeLinkPath ], { log : true , throwError : true });
273
+ } else {
274
+ runCommand (" chmod" , [" +x" , realPath ], { log : true , throwError : true });
275
+ runCommand (" sudo" , [" rm" , linkPath ], { log : true , throwError : false });
276
+ runCommand (" sudo" , [" ln" , " -s" , realPath , linkPath ], { log : true , throwError : true });
277
+ }
263
278
}
264
279
265
280
public static function updateHmm () {
@@ -268,8 +283,12 @@ class Shell {
268
283
}
269
284
270
285
public static function removeHmm () {
271
- // TODO: windows support?
272
- runCommand (" sudo" , [" rm" , hmm.commands. SetupCommand .HMM_LINK_PATH ], { log : true , throwError : true });
286
+ var linkPath = hmm.commands. SetupCommand .getLinkPath ();
287
+ if (isWin ) {
288
+ runCommand (" del" , [linkPath ], { log : true , throwError : true });
289
+ } else {
290
+ runCommand (" sudo" , [" rm" , linkPath ], { log : true , throwError : true });
291
+ }
273
292
haxelib ([" --global" , " remove" , " hmm" ], { log : true , throwError : true });
274
293
}
275
294
0 commit comments