diff --git a/src/bin/Service.hx b/src/bin/Service.hx new file mode 100644 index 0000000..7537de5 --- /dev/null +++ b/src/bin/Service.hx @@ -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): Bool { + switch (res) { + case Success(_): + return true; + case Failure(e): + this.handle.write(e); + return false; + } + } +} \ No newline at end of file diff --git a/src/kernel/binstore/BinStore.hx b/src/kernel/binstore/BinStore.hx index a128053..39e8412 100644 --- a/src/kernel/binstore/BinStore.hx +++ b/src/kernel/binstore/BinStore.hx @@ -1,15 +1,16 @@ package kernel.binstore; +import bin.Service; import bin.LSPS; import bin.Turtle; import bin.Terminal; -import haxe.ds.ReadOnlyArray; import bin.Redstone; import bin.Net; import bin.KernelLog; import bin.HelloWorld; import bin.GPS; import bin.Disk; +import haxe.ds.ReadOnlyArray; class BinStore { public static var instance: BinStore; @@ -23,12 +24,13 @@ class BinStore { {c: Redstone, name: "Redstone", aliases: ["redstone","rs"]}, {c: Terminal, name: "Terminal", aliases: ["terminal","term"]}, {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) private function new() { - + } public function getBinByName(name:String):Null {