Reformat directories recursively
This commit is contained in:
parent
4b0a88447b
commit
b1bf201a92
1 changed files with 13 additions and 3 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue