Skip to content

Commit 8533772

Browse files
committed
Submit to haxelib
1 parent 2e72c82 commit 8533772

File tree

11 files changed

+60
-13
lines changed

11 files changed

+60
-13
lines changed

haxelib.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"tags": ["tools"],
66
"description": "Local haxelib installation helper",
7-
"version": "0.0.6",
7+
"version": "0.0.7",
88
"classPath": "src/",
99
"releasenote": "Testing",
1010
"contributors": ["andywhite37"],

hmm

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
haxelib --global run hmm "$@"

run.n

1.25 KB
Binary file not shown.

src/hmm/Hmm.hx

+18-11
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,46 @@ package hmm;
33
import hmm.commands.*;
44
import hmm.utils.Log;
55
import hmm.utils.Shell;
6+
using Lambda;
67

78
class Hmm {
8-
public static var commands(default, null) : Map<String, ICommand>;
9+
public static var commandMap(default, null) : Map<String, ICommand>;
910

1011
public static function main() {
1112
var args = Sys.args();
1213

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()
1719
];
1820

19-
var command = "";
21+
var commandType = "";
22+
23+
Shell.hmmDirectory = Sys.getCwd();
2024

2125
if (args.length == 2) {
2226
// When running via `haxelib run` the current working directory is added to the end of the args list.
2327
// Also, Sys.getCwd() gets the location of the haxelib install not the actual working directory.
2428
Shell.workingDirectory = args.pop();
25-
command = args.pop();
29+
commandType = args.pop();
2630
} else if (args.length == 1) {
2731
Shell.workingDirectory = Sys.getEnv("PWD");
28-
command = args.pop();
32+
commandType = args.pop();
2933
} else {
3034
showUsage();
3135
}
3236

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');
3542
Sys.exit(1);
3643
}
3744

38-
commands[command].run();
45+
command.run();
3946
}
4047

4148
static function showUsage() {

src/hmm/commands/CleanCommand.hx

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package hmm.commands;
33
import hmm.utils.Shell;
44

55
class CleanCommand implements ICommand {
6+
public var type(default, null) = "clean";
7+
68
public function new() {
79
}
810

src/hmm/commands/ICommand.hx

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package hmm.commands;
22

33
interface ICommand {
4+
public var type(default, null) : String;
45
public function run() : Void;
56
}

src/hmm/commands/InstallCommand.hx

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import sys.FileSystem;
55
import sys.io.File;
66

77
class InstallCommand implements ICommand {
8+
public var type(default, null) = "install";
9+
810
public function new() {
911
}
1012

src/hmm/commands/SetupCommand.hx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package hmm.commands;
2+
3+
import sys.FileSystem;
4+
import sys.io.File;
5+
import haxe.io.Path;
6+
import hmm.utils.Shell;
7+
8+
class SetupCommand implements ICommand {
9+
public static var HMM_LINK_PATH = "/usr/local/bin/hmm";
10+
11+
public var type(default, null) = "setup";
12+
13+
public function new() {
14+
}
15+
16+
public function run() {
17+
Shell.symbolicLink(getHmmScriptFilePath(), HMM_LINK_PATH);
18+
}
19+
20+
function getHmmScriptFilePath() {
21+
return Path.join([Shell.hmmDirectory, "hmm"]);
22+
}
23+
}

src/hmm/commands/UpdateCommand.hx

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import sys.FileSystem;
55
import sys.io.File;
66

77
class UpdateCommand implements ICommand {
8+
public var type(default, null) = "update";
89
public function new() {
910
}
1011

src/hmm/utils/Shell.hx

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using hmm.utils.AnsiColors;
66

77
class Shell {
88
public static var workingDirectory(default, default) : String = "";
9+
public static var hmmDirectory(default, default) : String = "";
910

1011
public static function checkWorkingDirectory() {
1112
Log.info(workingDirectory);
@@ -71,6 +72,13 @@ class Shell {
7172
return command("haxelib", args);
7273
}
7374

75+
public static function symbolicLink(realPath : String, linkPath : String) {
76+
if (FileSystem.exists(linkPath)) {
77+
command("rm", [linkPath]);
78+
}
79+
command("ln", ["-s", realPath, linkPath]);
80+
}
81+
7482
public static function command(cmd : String, ?args : Array<String>) : Int {
7583
Log.shell('$cmd ${args.join(" ")}'.yellow());
7684
//return 0;

submit

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ haxe build.hxml
1010
git add -A
1111
git commit -m 'Submit to haxelib'
1212

13-
zip -r hmm.zip LICENSE README.md build.hxml haxelib.json run.n src
13+
zip -r hmm.zip LICENSE README.md build.hxml haxelib.json hmm run.n src
1414

1515
haxelib submit hmm.zip

0 commit comments

Comments
 (0)