Skip to content

Commit

Permalink
Adapting to new guardrail API
Browse files Browse the repository at this point in the history
  • Loading branch information
Devon Stewart committed Jan 9, 2019
1 parent 88d8db7 commit 7ef2635
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 17 additions & 9 deletions src/main/scala/com/twilio/swagger/sbt/Tasks.scala
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7ef2635

Please sign in to comment.