From 3e993b84ebd1caa2e4cb4f4c912b01973a6d115d Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Mon, 5 Aug 2024 15:41:03 +0200 Subject: [PATCH] added turtle ctl dig command --- src/bin/TurtleCtl.hx | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/bin/TurtleCtl.hx b/src/bin/TurtleCtl.hx index 46b30da..4dd8a0c 100644 --- a/src/bin/TurtleCtl.hx +++ b/src/bin/TurtleCtl.hx @@ -96,6 +96,20 @@ class TurtleCtl extends CLIAppBase { return Success(null); }, 1); }, [Optional(String("to"))]); + + registerAsyncSubcommand("dig", (args) -> { + var direction = args.getString("direction"); + switch (direction) { + case "front" | "f": + return asynPerform(() -> Turtle.dig(Front), 1); + case "top" | "t" | "up" | "u": + return asynPerform(() -> Turtle.dig(Up), 1); + case "bot" | "bottom" | "b" | "down" | "d": + return asynPerform(() -> Turtle.dig(Down), 1); + default: + return Future.sync(false); + } + }, [String("direction")]); } private function asynPerform(op:Void->Outcome, times:Int):Future { @@ -134,18 +148,4 @@ class TurtleCtl extends CLIAppBase { return null; }); } - - private function parseTimes(args:Array):Int { - if (args.length > 0) { - var num = Std.parseInt(args[0]); - if (num == null) { - handle.writeLine("Failed to parse args"); - return 0; - } else { - return num; - } - } else { - return 1; - } - } }