- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove dependency from on zio-config from `tools` * Add mima exclusions
1 parent
6393a7f
commit 1e67c31
Showing
9 changed files
with
134 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
codegen-sbt/src/main/scala/caliban/codegen/OptionsParser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package caliban.codegen | ||
|
||
import caliban.tools.Options | ||
import zio.config.magnolia.Descriptor | ||
import zio.config.{ read, ConfigDescriptor, ConfigSource } | ||
import zio.{ UIO, ZIO } | ||
|
||
object OptionsParser { | ||
final private case class RawOptions( | ||
scalafmtPath: Option[String], | ||
headers: Option[List[String]], | ||
packageName: Option[String], | ||
clientName: Option[String], | ||
genView: Option[Boolean], | ||
effect: Option[String], | ||
scalarMappings: Option[List[String]], | ||
imports: Option[List[String]], | ||
abstractEffectType: Option[Boolean], | ||
splitFiles: Option[Boolean], | ||
enableFmt: Option[Boolean], | ||
extensibleEnums: Option[Boolean], | ||
preserveInputNames: Option[Boolean], | ||
supportIsRepeatable: Option[Boolean], | ||
addDerives: Option[Boolean], | ||
envForDerives: Option[String] | ||
) | ||
|
||
private object DescriptorUtils { | ||
def from[A](configSource: ConfigSource)(implicit config: Descriptor[A]): ConfigDescriptor[A] = | ||
Descriptor.descriptor[A] from configSource | ||
} | ||
|
||
def fromArgs(args: List[String]): UIO[Option[Options]] = | ||
args match { | ||
case schemaPath :: toPath :: other => | ||
val configSource: ConfigSource = | ||
ConfigSource.fromCommandLineArgs( | ||
args = other, | ||
keyDelimiter = Some('.'), | ||
valueDelimiter = Some(',') | ||
) | ||
val configDescriptor: ConfigDescriptor[RawOptions] = DescriptorUtils.from[RawOptions](configSource) | ||
|
||
read[RawOptions](configDescriptor).map { rawOpts => | ||
Options( | ||
schemaPath, | ||
toPath, | ||
rawOpts.scalafmtPath, | ||
rawOpts.headers.map { | ||
_.flatMap { rawHeader => | ||
rawHeader.split(":").toList match { | ||
case name :: values if values.nonEmpty => Some(Options.Header(name, values.mkString(":"))) | ||
case _ => None | ||
} | ||
} | ||
}, | ||
rawOpts.packageName, | ||
rawOpts.clientName, | ||
rawOpts.genView, | ||
rawOpts.effect, | ||
rawOpts.scalarMappings.map { | ||
_.flatMap { rawMapping => | ||
rawMapping.split(":").toList match { | ||
case name :: value :: Nil => Some(name -> value) | ||
case _ => None | ||
} | ||
}.toMap | ||
}, | ||
rawOpts.imports, | ||
rawOpts.abstractEffectType, | ||
rawOpts.splitFiles, | ||
rawOpts.enableFmt, | ||
rawOpts.extensibleEnums, | ||
rawOpts.preserveInputNames, | ||
rawOpts.supportIsRepeatable, | ||
rawOpts.addDerives, | ||
rawOpts.envForDerives | ||
) | ||
}.option | ||
case _ => ZIO.none | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
codegen-sbt/src/sbt-test/codegen/test-compile-newtype/project/plugins.sbt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
sys.props.get("plugin.version") match { | ||
case Some(x) => addSbtPlugin("com.github.ghostdogpr" % "caliban-codegen-sbt" % x) | ||
case _ => sys.error("""|The system property 'plugin.version' is not defined. | ||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin) | ||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters