fancadescala/recipe/src/tf/bug/fancade/recipe/Main.scala

56 lines
1.6 KiB
Scala

package tf.bug.fancade.recipe
import cats.implicits._
import com.monovore.decline.effect.CommandIOApp
import cats.effect.{ExitCode, IO}
import com.monovore.decline.Opts
import java.nio.file.Path
import com.monovore.decline.Argument
object Main extends CommandIOApp(
name = "fancade-recipe",
header = "Fancade recipe creator and format helper",
version = "2.0.0",
) {
sealed trait InFormat
object InFormat {
implicit val arg: Argument[InFormat] = Argument.fromMap("input-format", Map(
"json" -> FancadeStackJson,
"fcl" -> FancadeLisp,
))
}
sealed trait OutFormat
object OutFormat {
implicit val arg: Argument[OutFormat] = Argument.fromMap("output-format", Map(
"json" -> FancadeStackJson,
"txt" -> Recipe,
"bin" -> Level,
))
}
case object FancadeStackJson extends InFormat with OutFormat
case object FancadeLisp extends InFormat
case object Recipe extends OutFormat
case object Level extends OutFormat
case class Compile(in: InFormat, inFile: Path, out: OutFormat, outFile: Path)
val compileOpts = {
val inFormatOpts = Opts.argument[InFormat]("input-format")
val inFileOpts = Opts.argument[Path]("input-path")
val outFormatOpts = Opts.argument[OutFormat]("output-format")
val outFileOpts = Opts.argument[Path]("output-path")
Opts.subcommand("compile", "Converts between script formats") {
(inFormatOpts, inFileOpts, outFormatOpts, outFileOpts).mapN(Compile)
}
}
override def main: Opts[IO[ExitCode]] = compileOpts.map {
case Compile(in, _, out, _) =>
IO(println(s"hello $in $out")).as(ExitCode.Success)
}
}