added turtle ctl dig command

This commit is contained in:
Niklas Kapelle 2024-08-05 15:41:03 +02:00
parent 09fef78f9a
commit 3e993b84eb
Signed by: niklas
GPG Key ID: 4EB651B36D841D16

View File

@ -96,6 +96,20 @@ class TurtleCtl extends CLIAppBase {
return Success(null); return Success(null);
}, 1); }, 1);
}, [Optional(String("to"))]); }, [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<Noise, String>, times:Int):Future<Bool> { private function asynPerform(op:Void->Outcome<Noise, String>, times:Int):Future<Bool> {
@ -134,18 +148,4 @@ class TurtleCtl extends CLIAppBase {
return null; return null;
}); });
} }
private function parseTimes(args:Array<String>):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;
}
}
} }