fix: remove implicit val causing conflicts with parsing cli arguments

This commit is contained in:
Jonny
2025-03-03 02:10:18 +00:00
parent 19e7ce4c11
commit f24aecffa3

View File

@@ -18,7 +18,7 @@ import org.typelevel.log4cats.slf4j.Slf4jLogger
import org.typelevel.log4cats.Logger
import assemblyIR as asm
import java.nio.file.Paths
import cats.data.ValidatedNel
/*
TODO:
@@ -30,34 +30,30 @@ TODO:
6) errors can be handled more gracefully probably
*/
given Argument[Path] = Argument.from("path") { str =>
val path =
if (str.startsWith("~")) Paths.get(System.getProperty("user.home"), str.drop(1)) // Expand ~
else Paths.get(str).toAbsolutePath.normalize() // TODO: normalize or not?
if (path.toString.endsWith(".wacc")) {
(
Either.cond(Files.exists(path), path, s"File '${path.toAbsolutePath}' does not exist"),
Either.cond(
Files.isRegularFile(path),
path,
s"File '${path.toAbsolutePath}' must be a regular file"
)
).mapN((_, _) => path).toValidatedNel
} else {
Right(path).toValidatedNel
}
}
given logger: Logger[IO] = Slf4jLogger.getLogger[IO]
val logOpt: Opts[Boolean] =
Opts.flag("log", "Enable logging for additional compilation details", short = "l").orFalse
val outputOpt: Opts[Option[Path]] =
Opts.option[Path]("output", "Specify path for output assembly file(s)").orNone
def validateFile(path: Path): ValidatedNel[String, Path] = {
(for {
// TODO: redundant 2nd parameter :(
_ <- Either.cond(Files.exists(path), (), s"File '${path}' does not exist")
_ <- Either.cond(Files.isRegularFile(path), (), s"File '${path}' must be a regular file")
_ <- Either.cond(path.toString.endsWith(".wacc"), (), "File must have .wacc extension")
} yield path).toValidatedNel
}
val filesOpt: Opts[NonEmptyList[Path]] = Opts.arguments[Path]("files")
val filesOpt: Opts[NonEmptyList[Path]] =
Opts.arguments[Path]("files").mapValidated {
_.traverse(validateFile)
}
// TODO: Is intermediate String necessary
val outputOpt: Opts[Option[Path]] =
Opts
.option[Path]("output", metavar = "path", help = "Output directory for compiled files.")
.orNone
def frontend(
contents: String