Files
cc-haxe/src/bin/srsc/CLI.hx
2023-06-07 21:29:29 +02:00

75 lines
1.6 KiB
Haxe

package bin.srsc;
import kernel.net.Package.NetworkID;
import lib.RessourceNames;
import lib.CLIAppBase;
using tink.CoreApi;
class CLI extends CLIAppBase {
public function new() {
registerAsyncSubcommand("get", (args) -> {
if (args.length < 1) {
handle.writeLine("Not enough arguments");
return Future.sync(false);
}
return RessourceNames.get(args[0]).map((res) -> {
switch (res) {
case Success(data):
if (data == null) {
handle.writeLine("Not found");
} else {
handle.writeLine("Found: " + data);
}
case Failure(error):
handle.writeLine("Error: " + error);
}
return true;
});
}, "<name>");
registerAsyncSubcommand("register", (args) -> {
if (args.length < 2) {
handle.writeLine("Not enough arguments");
return Future.sync(false);
}
var id:NetworkID = Std.parseInt(args[1]);
if (id == null) {
handle.writeLine("Invalid id");
return Future.sync(false);
}
return RessourceNames.register(args[0], id).map((res) -> {
switch (res) {
case Success(data):
handle.writeLine("Success");
case Failure(error):
handle.writeLine("Error: " + error);
}
return true;
});
}, "<name> <id>");
registerAsyncSubcommand("unregister", (args) -> {
if (args.length < 1) {
handle.writeLine("Not enough arguments");
return Future.sync(false);
}
return RessourceNames.unregister(args[0]).map((res) -> {
switch (res) {
case Success(data):
handle.writeLine("Success");
case Failure(error):
handle.writeLine("Error: " + error);
}
return true;
});
}, "<name>");
}
}