From b1bf201a9274819fb3a5822f74b0f1c2883dc7c9 Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 4 Sep 2024 19:20:26 +0200 Subject: [PATCH] Reformat directories recursively --- .../scala/de/plugh/asciiprooftree/Main.scala | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/scala/de/plugh/asciiprooftree/Main.scala b/src/main/scala/de/plugh/asciiprooftree/Main.scala index 872e7fb..088a3db 100644 --- a/src/main/scala/de/plugh/asciiprooftree/Main.scala +++ b/src/main/scala/de/plugh/asciiprooftree/Main.scala @@ -4,6 +4,7 @@ import de.plugh.asciiprooftree.file.Formatter import org.rogach.scallop.* import java.nio.file.{Files, Path} +import scala.jdk.StreamConverters.* class Conf(args: Seq[String]) extends ScallopConf(args): val path: ScallopOption[Path] = trailArg[Path]() @@ -13,6 +14,15 @@ class Conf(args: Seq[String]) extends ScallopConf(args): @main def main(args: String*): Unit = val conf = new Conf(args) - val text = Files.readString(conf.path()) - val newText = Formatter.reformat(text, marker = conf.marker()) - Files.writeString(conf.path(), newText) + reformat(conf.path(), conf.marker()) + +def reformat(path: Path, marker: String): Unit = + if Files.isDirectory(path) then + val files = Files.list(path).toScala(Seq) + for file <- files do reformat(file, marker) + else if Files.isRegularFile(path) then + val text = Files.readString(path) + val newText = Formatter.reformat(text, marker = marker) + if text != newText then + println(path) + Files.writeString(path, newText)