added service bin

This commit is contained in:
Djeeberjr 2023-05-29 12:50:11 +02:00
parent f35c98f912
commit 5985b0c8be
2 changed files with 68 additions and 3 deletions

63
src/bin/Service.hx Normal file
View File

@ -0,0 +1,63 @@
package bin;
import kernel.service.ServiceManager;
import lib.CLIAppBase;
using tink.CoreApi;
class Service extends CLIAppBase {
public function new() {
registerSyncSubcommand("start", (args) ->{
if (args.length < 1) {
return false;
}
var name = args[0];
var result = ServiceManager.instace.start(name);
return handleResult(result);
},"Start a service");
registerSyncSubcommand("stop", (args) ->{
if (args.length < 1) {
return false;
}
var name = args[0];
var result = ServiceManager.instace.stop(name);
return handleResult(result);
},"Stop a service");
registerSyncSubcommand("register", (args) ->{
if (args.length < 2) {
return false;
}
var name = args[0];
var binName = args[1];
var rest = args.slice(2);
var result = ServiceManager.instace.register(name, binName, rest);
return handleResult(result);
},"Register a new service");
registerSyncSubcommand("unregister", (args) ->{
return true;
},"Unregister a service");
registerSyncSubcommand("list", (args) ->{
return true;
},"List all services");
}
private function handleResult(res: Outcome<Noise,String>): Bool {
switch (res) {
case Success(_):
return true;
case Failure(e):
this.handle.write(e);
return false;
}
}
}

View File

@ -1,15 +1,16 @@
package kernel.binstore; package kernel.binstore;
import bin.Service;
import bin.LSPS; import bin.LSPS;
import bin.Turtle; import bin.Turtle;
import bin.Terminal; import bin.Terminal;
import haxe.ds.ReadOnlyArray;
import bin.Redstone; import bin.Redstone;
import bin.Net; import bin.Net;
import bin.KernelLog; import bin.KernelLog;
import bin.HelloWorld; import bin.HelloWorld;
import bin.GPS; import bin.GPS;
import bin.Disk; import bin.Disk;
import haxe.ds.ReadOnlyArray;
class BinStore { class BinStore {
public static var instance: BinStore; public static var instance: BinStore;
@ -23,12 +24,13 @@ class BinStore {
{c: Redstone, name: "Redstone", aliases: ["redstone","rs"]}, {c: Redstone, name: "Redstone", aliases: ["redstone","rs"]},
{c: Terminal, name: "Terminal", aliases: ["terminal","term"]}, {c: Terminal, name: "Terminal", aliases: ["terminal","term"]},
{c: Turtle, name: "Turtle", aliases: ["turtle"]}, {c: Turtle, name: "Turtle", aliases: ["turtle"]},
{c: LSPS, name: "PM", aliases: ["lsps"]} {c: LSPS, name: "PM", aliases: ["lsps"]},
{c: Service, name: "Service", aliases: ["service","srv"]}
]; ];
@:allow(kernel.Init) @:allow(kernel.Init)
private function new() { private function new() {
} }
public function getBinByName(name:String):Null<Bin> { public function getBinByName(name:String):Null<Bin> {