added inspect command to turtleCtl

This commit is contained in:
Niklas Kapelle 2024-10-20 23:23:58 +02:00
parent 90b4015ba1
commit fe17b4fd67
Signed by: niklas
GPG Key ID: 4EB651B36D841D16

View File

@ -1,5 +1,6 @@
package bin; package bin;
import kernel.turtle.Types.ToolSide;
import lib.turtle.Helper; import lib.turtle.Helper;
import kernel.turtle.TurtleMutex; import kernel.turtle.TurtleMutex;
import kernel.turtle.Turtle; import kernel.turtle.Turtle;
@ -116,6 +117,28 @@ class TurtleCtl extends CLIAppBase {
var len = args.getInt("length"); var len = args.getInt("length");
return asynPerform(Helper.combine.bind([Turtle.digEmpty.bind(Front), Turtle.forward, Turtle.digEmpty.bind(Up)]), len); return asynPerform(Helper.combine.bind([Turtle.digEmpty.bind(Front), Turtle.forward, Turtle.digEmpty.bind(Up)]), len);
}, [Int("length")]); }, [Int("length")]);
registerSyncSubcommand("inspect", (args) -> {
var res = Turtle.inspect(Front);
switch res {
case Failure(err):
handle.writeLine("Failed: " + err);
return false;
case Success(data):
handle.writeLine('Name: ${data.name}');
handle.writeLine("Tags:");
for (tag in data.tags.sortByName()) {
handle.writeLine(' ${tag}');
}
handle.writeLine("State:");
handle.writeLine(data.state);
}
return true;
}, []);
} }
private function asynPerform(op:Void->Outcome<Noise, String>, times:Int):Future<Bool> { private function asynPerform(op:Void->Outcome<Noise, String>, times:Int):Future<Bool> {