Last active
April 25, 2025 14:25
-
-
Save kastoestoramadus/8d2143bdcb49fbb163fdd0f99a39fbc0 to your computer and use it in GitHub Desktop.
second
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.ekrich.config | |
import java.io.File | |
import java.nio.file.{Path, Paths} | |
import java.nio.file.{Files, Paths} | |
import java.nio.charset.StandardCharsets | |
object Formatter { | |
def main(args: Array[String]): Unit = { | |
println(s"Running HOCON formatter. pwd: ${new File(".").getAbsolutePath}") | |
assert(args.length > 0) | |
val targetFilePathStr = args(0) | |
reformatFile(targetFilePathStr) | |
} | |
val parseOptions = ConfigParseOptions.defaults.setAllowMissing(true) | |
val renderOptions = ConfigRenderOptions.defaults | |
.setJson(false) | |
.setOriginComments(false) | |
.setComments(true) | |
.setFormatted(true) | |
def fmtFileToStr(filePathStr: String): String = | |
ConfigFactory | |
.parseFile(new File(filePathStr), parseOptions) | |
.root | |
.render(renderOptions) | |
def reformatFile(filePathStr: String): Unit = { | |
val formattedStr = fmtFileToStr(filePathStr) | |
Files.write( | |
Paths.get(filePathStr), | |
formattedStr.getBytes(StandardCharsets.UTF_8) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment