From 7ef26359fbf1dbbf78d21f4cccf54800a09829cf Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Tue, 8 Jan 2019 18:43:36 -0800 Subject: [PATCH] Adapting to new guardrail API --- build.sbt | 4 ++- .../scala/com/twilio/swagger/sbt/Tasks.scala | 26 ++++++++++++------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/build.sbt b/build.sbt index 238d43d..92ab5b6 100644 --- a/build.sbt +++ b/build.sbt @@ -29,7 +29,9 @@ developers := List( ) scalaVersion := "2.12.6" -scalacOptions += "-feature" +scalacOptions ++= List("-feature", "-Xexperimental") + +addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.9") // Versioning enablePlugins(GitBranchPrompt) diff --git a/src/main/scala/com/twilio/swagger/sbt/Tasks.scala b/src/main/scala/com/twilio/swagger/sbt/Tasks.scala index 86ef307..3605742 100644 --- a/src/main/scala/com/twilio/swagger/sbt/Tasks.scala +++ b/src/main/scala/com/twilio/swagger/sbt/Tasks.scala @@ -1,24 +1,32 @@ package com.twilio.guardrail package sbt -import cats.~> -import cats.free.Free +import _root_.sbt.{FeedbackProvidedException, WatchSource} import cats.data.{EitherT, NonEmptyList, WriterT} -import cats.instances.all._ -import com.twilio.guardrail.{Common, CoreTarget} +import cats.free.Free +import cats.implicits._ +import cats.~> import com.twilio.guardrail.core.CoreTermInterp +import com.twilio.guardrail.languages.{ ScalaLanguage, LA } import com.twilio.guardrail.terms.{CoreTerm, CoreTerms, GetDefaultFramework} -import scala.language.higherKinds +import com.twilio.guardrail.{Common, CoreTarget} import scala.io.AnsiColor -import _root_.sbt.{FeedbackProvidedException, WatchSource} +import scala.language.higherKinds +import scala.meta._ class CodegenFailedException extends FeedbackProvidedException object Tasks { def guardrailTask(tasks: List[GuardrailPlugin.Args], sourceDir: java.io.File): Seq[java.io.File] = { val preppedTasks = tasks.map(_.copy(outputPath=Some(sourceDir.getPath))) - runM[CoreTerm](preppedTasks).foldMap(CoreTermInterp) - .fold({ + runM[ScalaLanguage, CoreTerm[ScalaLanguage, ?]](preppedTasks).foldMap(CoreTermInterp[ScalaLanguage]( + "akka-http", { + case "akka-http" => com.twilio.guardrail.generators.AkkaHttp + case "http4s" => com.twilio.guardrail.generators.Http4s + }, { + _.parse[Importer].toEither.bimap(err => UnparseableArgument("import", err.toString), importer => Import(List(importer))) + } + )).fold({ case MissingArg(args, Error.ArgName(arg)) => println(s"${AnsiColor.RED}Missing argument:${AnsiColor.RESET} ${AnsiColor.BOLD}${arg}${AnsiColor.RESET} (In block ${args})") throw new CodegenFailedException() @@ -53,7 +61,7 @@ object Tasks { tasks.flatMap(_.specPath.map(new java.io.File(_)).map(WatchSource(_))).toSeq } - private[this] def runM[F[_]](args: List[GuardrailPlugin.Args])(implicit C: CoreTerms[F]): Free[F, NonEmptyList[ReadSwagger[Target[List[WriteTree]]]]] = { + private[this] def runM[L <: LA, F[_]](args: List[GuardrailPlugin.Args])(implicit C: CoreTerms[L, F]): Free[F, NonEmptyList[ReadSwagger[Target[List[WriteTree]]]]] = { import C._ for {