Parse args with scallop
This commit is contained in:
parent
8f55c90980
commit
4b0a88447b
2 changed files with 11 additions and 16 deletions
|
|
@ -6,4 +6,5 @@ lazy val root = project
|
||||||
name := "asciiprooftree",
|
name := "asciiprooftree",
|
||||||
version := "0.0.0",
|
version := "0.0.0",
|
||||||
scalaVersion := scala3Version,
|
scalaVersion := scala3Version,
|
||||||
|
libraryDependencies += "org.rogach" %% "scallop" % "5.1.0",
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,18 @@
|
||||||
package de.plugh.asciiprooftree
|
package de.plugh.asciiprooftree
|
||||||
|
|
||||||
import de.plugh.asciiprooftree.file.Formatter
|
import de.plugh.asciiprooftree.file.Formatter
|
||||||
|
import org.rogach.scallop.*
|
||||||
|
|
||||||
import java.nio.file.{Files, Path}
|
import java.nio.file.{Files, Path}
|
||||||
|
|
||||||
@main
|
class Conf(args: Seq[String]) extends ScallopConf(args):
|
||||||
def main(args: String*): Unit = args match
|
val path: ScallopOption[Path] = trailArg[Path]()
|
||||||
case Seq() => run()
|
val marker: ScallopOption[String] = opt[String](default = Some("§"))
|
||||||
case Seq(path) => run(Path.of(path))
|
verify()
|
||||||
case Seq(path, marker) => run(Path.of(path), marker)
|
|
||||||
case _ =>
|
|
||||||
println("Usage: asciiprooftree [path] [marker]")
|
|
||||||
System.exit(1)
|
|
||||||
|
|
||||||
@main
|
@main
|
||||||
def testMain(path: String): Unit = run(Path.of(path))
|
def main(args: String*): Unit =
|
||||||
|
val conf = new Conf(args)
|
||||||
def run(path: Path = Path.of(""), marker: String = "§"): Unit =
|
val text = Files.readString(conf.path())
|
||||||
println(s"Path: $path")
|
val newText = Formatter.reformat(text, marker = conf.marker())
|
||||||
println(s"Marker: $marker")
|
Files.writeString(conf.path(), newText)
|
||||||
val text = Files.readString(path)
|
|
||||||
val newText = Formatter.reformat(text, marker = marker)
|
|
||||||
Files.writeString(path, newText)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue