fix: remove implicit val causing conflicts with parsing cli arguments
This commit is contained in:
@@ -18,7 +18,7 @@ import org.typelevel.log4cats.slf4j.Slf4jLogger
|
|||||||
import org.typelevel.log4cats.Logger
|
import org.typelevel.log4cats.Logger
|
||||||
|
|
||||||
import assemblyIR as asm
|
import assemblyIR as asm
|
||||||
import java.nio.file.Paths
|
import cats.data.ValidatedNel
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
@@ -30,34 +30,30 @@ TODO:
|
|||||||
6) errors can be handled more gracefully probably
|
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]
|
given logger: Logger[IO] = Slf4jLogger.getLogger[IO]
|
||||||
|
|
||||||
val logOpt: Opts[Boolean] =
|
val logOpt: Opts[Boolean] =
|
||||||
Opts.flag("log", "Enable logging for additional compilation details", short = "l").orFalse
|
Opts.flag("log", "Enable logging for additional compilation details", short = "l").orFalse
|
||||||
|
|
||||||
val outputOpt: Opts[Option[Path]] =
|
def validateFile(path: Path): ValidatedNel[String, Path] = {
|
||||||
Opts.option[Path]("output", "Specify path for output assembly file(s)").orNone
|
(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(
|
def frontend(
|
||||||
contents: String
|
contents: String
|
||||||
|
|||||||
Reference in New Issue
Block a user