improved exporter

This commit is contained in:
2023-06-26 19:06:24 +02:00
parent 4dcc060e9a
commit 7bfe594b4b
7 changed files with 118 additions and 82 deletions

58
src/bin/exporter/Res.hx Normal file
View File

@@ -0,0 +1,58 @@
package bin.exporter;
import lib.exporter.Export;
import lib.exporter.IExportable;
import kernel.peripherals.Peripherals.Peripheral;
import kernel.service.ServiceManager;
import lib.exporter.Import;
import lib.CLIAppBase;
class Res extends CLIAppBase {
public function new() {
registerAsyncSubcommand("get", (args)->{
var url = args[0];
return Import.get(url).map((res)->{
switch (res){
case Success(data):
handle.writeLine(Std.string(data));
case Failure(err):
handle.writeLine("Error: ");
handle.writeLine(Std.string(err));
}
return true;
});
},"<url>");
registerAsyncSubcommand("register",(args)->{
var srv: Null<ResManager> = ServiceManager.instance.get("resmgr");
var addr = args[0];
var name = args[1];
if (srv == null) {
handle.writeLine("Error: resmgr not found");
return false;
}
var perf: kernel.peripherals.Redstone = Peripheral.instance.getRedstone(addr);
if (perf == null) {
handle.writeLine("Error: peripheral not found");
return false;
}
return srv.register(name,new Export(perf)).map((res)->{
switch (res){
case Success(_):
handle.writeLine("Success");
return true;
case Failure(err):
handle.writeLine("Error: ");
handle.writeLine(Std.string(err));
return false;
}
});
},"<addr> <name>");
}
}