diff --git a/build.sc b/build.sc index a041654..944ea7a 100644 --- a/build.sc +++ b/build.sc @@ -8,7 +8,7 @@ import com.github.lolgab.mill.mima._ val scala212 = "2.12.17" val scala213 = "2.13.10" -val scala3 = "3.1.3" +val scala3 = "3.3.1" val osLib = "0.9.3" val acyclic = "0.3.11" @@ -51,19 +51,23 @@ trait MainArgsPublishModule super.scalacOptions() ++ Option.when(!isScala3(scalaVersion()))("-P:acyclic:force") - def scalacPluginIvyDeps = + def scalacPluginIvyDeps = T{ super.scalacPluginIvyDeps() ++ - Option.when(!isScala3(scalaVersion()))(ivy"com.lihaoyi:::acyclic:${acyclic}") + Agg(ivy"com.lihaoyi::unroll-plugin:0.1.12") ++ + Option.when(!isScala3(scalaVersion()))(ivy"com.lihaoyi:::acyclic:${acyclic}") + } def compileIvyDeps = super.compileIvyDeps() ++ - Agg.when(!isScala3(crossScalaVersion))( - ivy"com.lihaoyi:::acyclic:${acyclic}", - ivy"org.scala-lang:scala-reflect:$crossScalaVersion" - ) + Agg.when(!isScala3(crossScalaVersion))( + ivy"com.lihaoyi:::acyclic:${acyclic}", + ivy"org.scala-lang:scala-reflect:$crossScalaVersion", + + ) def ivyDeps = Agg( - ivy"org.scala-lang.modules::scala-collection-compat::2.8.1" + ivy"com.lihaoyi::unroll-annotation:0.1.12", + ivy"org.scala-lang.modules::scala-collection-compat::2.8.1", ) } @@ -83,13 +87,13 @@ object mainargs extends Module { object js extends Cross[JSMainArgsModule](scalaVersions) trait JSMainArgsModule extends MainArgsPublishModule with ScalaJSModule { - def scalaJSVersion = "1.10.1" + def scalaJSVersion = "1.13.1" object test extends ScalaJSTests with CommonTestModule } object native extends Cross[NativeMainArgsModule](scalaVersions) trait NativeMainArgsModule extends MainArgsPublishModule with ScalaNativeModule { - def scalaNativeVersion = "0.4.7" + def scalaNativeVersion = "0.4.14" object test extends ScalaNativeTests with CommonTestModule } } diff --git a/mainargs/src/Parser.scala b/mainargs/src/Parser.scala index b9288c9..2e919bc 100644 --- a/mainargs/src/Parser.scala +++ b/mainargs/src/Parser.scala @@ -4,26 +4,16 @@ import acyclic.skipped import scala.language.experimental.macros import java.io.PrintStream - +import scala.annotation.unroll object ParserForMethods extends ParserForMethodsCompanionVersionSpecific class ParserForMethods[B](val mains: MethodMains[B]) { - @deprecated("Binary Compatibility Shim", "mainargs 0.6.0") - def helpText( - totalWidth: Int, - docsOnNewLine: Boolean, - customNames: Map[String, String], - customDocs: Map[String, String], - sorted: Boolean): String = { - helpText(totalWidth, docsOnNewLine, customNames, customDocs, sorted, Util.kebabCaseNameMapper) - } - def helpText( totalWidth: Int = 100, docsOnNewLine: Boolean = false, customNames: Map[String, String] = Map(), customDocs: Map[String, String] = Map(), - sorted: Boolean = true, - nameMapper: String => Option[String] = Util.kebabCaseNameMapper + @unroll sorted: Boolean = true, + @unroll nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): String = { Renderer.formatMainMethods( mains.value, @@ -36,14 +26,6 @@ class ParserForMethods[B](val mains: MethodMains[B]) { ) } - @deprecated("Binary compatibility shim, use other overload instead", "mainargs after 0.3.0") - private[mainargs] def helpText( - totalWidth: Int, - docsOnNewLine: Boolean, - customNames: Map[String, String], - customDocs: Map[String, String] - ): String = helpText(totalWidth, docsOnNewLine, customNames, customDocs, sorted = true) - def runOrExit( args: Seq[String], allowPositional: Boolean = false, @@ -74,28 +56,6 @@ class ParserForMethods[B](val mains: MethodMains[B]) { } } - def runOrThrow( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - totalWidth: Int, - printHelpOnExit: Boolean, - docsOnNewLine: Boolean, - autoPrintHelpAndExit: Option[(Int, PrintStream)], - customNames: Map[String, String], - customDocs: Map[String, String], - ): Any = runOrThrow( - args, - allowPositional, - allowRepeats, - totalWidth, - printHelpOnExit, - docsOnNewLine, - autoPrintHelpAndExit, - customNames, - customDocs, - ) - def runOrThrow( args: Seq[String], allowPositional: Boolean = false, @@ -106,7 +66,7 @@ class ParserForMethods[B](val mains: MethodMains[B]) { autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)), customNames: Map[String, String] = Map(), customDocs: Map[String, String] = Map(), - nameMapper: String => Option[String] = Util.kebabCaseNameMapper + @unroll nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): Any = { runEither( args, @@ -135,8 +95,8 @@ class ParserForMethods[B](val mains: MethodMains[B]) { autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)), customNames: Map[String, String] = Map(), customDocs: Map[String, String] = Map(), - sorted: Boolean = false, - nameMapper: String => Option[String] = Util.kebabCaseNameMapper + @unroll sorted: Boolean = false, + @unroll nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): Either[String, Any] = { if (autoPrintHelpAndExit.nonEmpty && args.take(1) == Seq("--help")) { val (exitCode, outputStream) = autoPrintHelpAndExit.get @@ -165,70 +125,11 @@ class ParserForMethods[B](val mains: MethodMains[B]) { } } - @deprecated("Binary compatibility shim, use other overload instead", "mainargs after 0.3.0") - private[mainargs] def runEither( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - totalWidth: Int, - printHelpOnExit: Boolean, - docsOnNewLine: Boolean, - autoPrintHelpAndExit: Option[(Int, PrintStream)], - customNames: Map[String, String], - customDocs: Map[String, String] - ): Either[String, Any] = runEither( - args, - allowPositional, - allowRepeats, - totalWidth, - printHelpOnExit, - docsOnNewLine, - autoPrintHelpAndExit, - customNames, - customDocs, - sorted = false - ) - - - - @deprecated("Binary Compatibility Shim", "mainargs 0.6.0") - def runEither( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - totalWidth: Int, - printHelpOnExit: Boolean, - docsOnNewLine: Boolean, - autoPrintHelpAndExit: Option[(Int, PrintStream)], - customNames: Map[String, String], - customDocs: Map[String, String], - sorted: Boolean - ): Either[String, Any] = runEither( - args, - allowPositional, - allowRepeats, - totalWidth, - printHelpOnExit, - docsOnNewLine, - autoPrintHelpAndExit, - customNames, - customDocs, - sorted, - Util.kebabCaseNameMapper - ) - @deprecated("Binary Compatibility Shim", "mainargs 0.6.0") - def runRaw( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - ): Result[Any] = runRaw( - args, allowPositional, allowRepeats, Util.kebabCaseNameMapper - ) def runRaw( args: Seq[String], allowPositional: Boolean = false, allowRepeats: Boolean = false, - nameMapper: String => Option[String] = Util.kebabCaseNameMapper + @unroll nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): Result[Any] = { runRaw0(args, allowPositional, allowRepeats, nameMapper) match { case Left(err) => err @@ -236,23 +137,11 @@ class ParserForMethods[B](val mains: MethodMains[B]) { } } - @deprecated("Binary Compatibility Shim", "mainargs 0.6.0") - def runRaw0( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - ): Either[Result.Failure.Early, (MainData[_, B], Result[Any])] = runRaw0( - args, - allowPositional, - allowRepeats, - Util.kebabCaseNameMapper - ) - def runRaw0( args: Seq[String], allowPositional: Boolean = false, allowRepeats: Boolean = false, - nameMapper: String => Option[String] = Util.kebabCaseNameMapper + @unroll nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): Either[Result.Failure.Early, (MainData[_, B], Result[Any])] = { for (tuple <- Invoker.runMains(mains, args, allowPositional, allowRepeats, nameMapper)) yield { val (errMsg, res) = tuple @@ -264,20 +153,13 @@ class ParserForMethods[B](val mains: MethodMains[B]) { object ParserForClass extends ParserForClassCompanionVersionSpecific class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) extends TokensReader.Class[T] { - @deprecated("Binary Compatibility Shim", "mainargs 0.6.0") - def helpText( - totalWidth: Int, - docsOnNewLine: Boolean, - customName: String, - customDoc: String, - sorted: Boolean): String = helpText(totalWidth, docsOnNewLine, customName, customDoc, sorted, Util.kebabCaseNameMapper) def helpText( totalWidth: Int = 100, docsOnNewLine: Boolean = false, customName: String = null, customDoc: String = null, - sorted: Boolean = true, + @unroll sorted: Boolean = true, nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): String = { Renderer.formatMainMethodSignature( @@ -293,39 +175,6 @@ class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) ) } - @deprecated("Binary compatibility shim, use other overload instead", "mainargs after 0.3.0") - private[mainargs] def helpText( - totalWidth: Int, - docsOnNewLine: Boolean, - customName: String, - customDoc: String - ): String = helpText(totalWidth, docsOnNewLine, customName, customDoc, sorted = true) - - @deprecated("Binary Compatibility Shim", "mainargs 0.6.0") - def constructOrExit( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - stderr: PrintStream, - totalWidth: Int, - printHelpOnExit: Boolean, - docsOnNewLine: Boolean, - autoPrintHelpAndExit: Option[(Int, PrintStream)], - customName: String, - customDoc: String): T = constructOrExit( - args, - allowPositional, - allowRepeats, - stderr, - totalWidth, - printHelpOnExit, - docsOnNewLine, - autoPrintHelpAndExit, - customName, - customDoc, - Util.kebabCaseNameMapper - ) - def constructOrExit( args: Seq[String], allowPositional: Boolean = false, @@ -337,7 +186,7 @@ class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)), customName: String = null, customDoc: String = null, - nameMapper: String => Option[String] = Util.kebabCaseNameMapper + @unroll nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): T = { constructEither( args, @@ -349,6 +198,7 @@ class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) autoPrintHelpAndExit, customName, customDoc, + sorted = false, nameMapper ) match { case Left(msg) => @@ -358,29 +208,6 @@ class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) } } - def constructOrThrow( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - totalWidth: Int, - printHelpOnExit: Boolean, - docsOnNewLine: Boolean, - autoPrintHelpAndExit: Option[(Int, PrintStream)], - customName: String, - customDoc: String, - ): T = constructOrThrow( - args, - allowPositional, - allowRepeats, - totalWidth, - printHelpOnExit, - docsOnNewLine, - autoPrintHelpAndExit, - customName, - customDoc, - Util.kebabCaseNameMapper - ) - def constructOrThrow( args: Seq[String], allowPositional: Boolean = false, @@ -391,7 +218,7 @@ class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)), customName: String = null, customDoc: String = null, - nameMapper: String => Option[String] = Util.kebabCaseNameMapper + @unroll nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): T = { constructEither( args, @@ -403,6 +230,7 @@ class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) autoPrintHelpAndExit, customName, customDoc, + sorted = false, nameMapper ) match { case Left(msg) => throw new Exception(msg) @@ -410,29 +238,6 @@ class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) } } - def constructEither( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - totalWidth: Int, - printHelpOnExit: Boolean, - docsOnNewLine: Boolean, - autoPrintHelpAndExit: Option[(Int, PrintStream)], - customName: String, - customDoc: String, - sorted: Boolean, - ): Either[String, T] = constructEither( - args, - allowPositional, - allowRepeats, - totalWidth, - printHelpOnExit, - docsOnNewLine, - autoPrintHelpAndExit, - customName, - customDoc, - sorted, - ) def constructEither( args: Seq[String], allowPositional: Boolean = false, @@ -443,8 +248,8 @@ class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) autoPrintHelpAndExit: Option[(Int, PrintStream)] = Some((0, System.out)), customName: String = null, customDoc: String = null, - sorted: Boolean = true, - nameMapper: String => Option[String] = Util.kebabCaseNameMapper + @unroll sorted: Boolean = true, + @unroll nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): Either[String, T] = { if (autoPrintHelpAndExit.nonEmpty && args.take(1) == Seq("--help")) { val (exitCode, outputStream) = autoPrintHelpAndExit.get @@ -469,48 +274,11 @@ class ParserForClass[T](val main: MainData[T, Any], val companion: () => Any) } } - /** binary compatibility shim. */ - private[mainargs] def constructEither( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - totalWidth: Int, - printHelpOnExit: Boolean, - docsOnNewLine: Boolean, - autoPrintHelpAndExit: Option[(Int, PrintStream)], - customName: String, - customDoc: String, - nameMapper: String => Option[String] - ): Either[String, T] = constructEither( - args, - allowPositional, - allowRepeats, - totalWidth, - printHelpOnExit, - docsOnNewLine, - autoPrintHelpAndExit, - customName, - customDoc, - sorted = true, - nameMapper = nameMapper - ) - - def constructRaw( - args: Seq[String], - allowPositional: Boolean, - allowRepeats: Boolean, - ): Result[T] = constructRaw( - args, - allowPositional, - allowRepeats, - nameMapper = Util.kebabCaseNameMapper - ) - def constructRaw( args: Seq[String], allowPositional: Boolean = false, allowRepeats: Boolean = false, - nameMapper: String => Option[String] = Util.kebabCaseNameMapper + @unroll nameMapper: String => Option[String] = Util.kebabCaseNameMapper ): Result[T] = { Invoker.construct[T](this, args, allowPositional, allowRepeats, nameMapper) }