diff --git a/src/bin/Redstone.hx b/src/bin/Redstone.hx index a269341..48dca00 100644 --- a/src/bin/Redstone.hx +++ b/src/bin/Redstone.hx @@ -1,44 +1,26 @@ package bin; -import kernel.ps.ProcessHandle; -import kernel.ps.Process; +import lib.CLIAppBase; import kernel.peripherals.Peripherals.Peripheral; -import kernel.peripherals.Side; using tink.CoreApi; -class Redstone implements Process { - public function new() {} +class Redstone extends CLIAppBase{ + public function new() { + registerSyncSubcommand("on", (args)-> { + Peripheral.instance.getRedstone(args[0]).setOutput(true); + return true; + }); - public function run(handle: ProcessHandle):Void { - var subcommand = handle.args[0]; + registerSyncSubcommand("off", (args)-> { + Peripheral.instance.getRedstone(args[0]).setOutput(false); + return true; + }); - if (subcommand == null) { - handle.write("Usage: redstone "); - return handle.close(false); - } - - var side:Null = handle.args[1]; - if (side == null) { - handle.write("Invalid side"); - return handle.close(false); - } - - switch (subcommand) { - case "on": - Peripheral.instance.getRedstone(side).setOutput(true); - case "off": - Peripheral.instance.getRedstone(side).setOutput(false); - case "get": - var value = Peripheral.instance.getRedstone(side).getAnalogInput(); - handle.write("Analog input: " + value); - case "help": - handle.write("Usage: redstone "); - default: - handle.write("Invalid subcommand"); - return handle.close(false); - } - - return handle.close(); + registerSyncSubcommand("get", (args)-> { + var value = Peripheral.instance.getRedstone(args[0]).getAnalogInput(); + handle.write("Analog input: " + value); + return true; + }); } }