mirror of https://github.com/sbt/sbt.git
[2.x] fix: Handle scala/toolkit.local when passed as argument to sbt new (#8887)
Running sbt new scala/toolkit.local with the template slug on the command line throws: The same templates work when chosen from the interactive menu (sbt new with no args). The code path for “arguments provided” only consulted external template resolvers (e.g. Giter8), which do not handle these built-in local templates.
This commit is contained in:
parent
d71fe5b7a3
commit
6821167032
|
|
@ -53,8 +53,14 @@ private[sbt] object TemplateCommandUtil {
|
|||
def terminate = TerminateAction :: s1.copy(remainingCommands = Nil)
|
||||
def reload = "reboot" :: s1.copy(remainingCommands = Nil)
|
||||
if (args0.nonEmpty) {
|
||||
run(infos, args0, s0.configuration, lm, globalBase, scalaModuleInfo, log)
|
||||
terminate
|
||||
args0 match {
|
||||
case arg :: Nil if arg.endsWith(".local") =>
|
||||
extracted.runInputTask(Keys.templateRunLocal, " " + arg, s0)
|
||||
reload
|
||||
case _ =>
|
||||
run(infos, args0, s0.configuration, lm, globalBase, scalaModuleInfo, log)
|
||||
terminate
|
||||
}
|
||||
} else {
|
||||
fortifyArgs(templateDescriptions.toList) match {
|
||||
case Nil => terminate
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* sbt
|
||||
* Copyright 2023, Scala center
|
||||
* Copyright 2011 - 2022, Lightbend, Inc.
|
||||
* Copyright 2008 - 2010, Mark Harrah
|
||||
* Licensed under Apache License 2.0 (see LICENSE)
|
||||
*/
|
||||
|
||||
package sbt
|
||||
|
||||
import sbt.util.Logger
|
||||
|
||||
object TemplateCommandUtilTest extends verify.BasicTestSuite:
|
||||
|
||||
private val localTemplateSlugs = List(
|
||||
"scala/toolkit.local",
|
||||
"typelevel/toolkit.local",
|
||||
"sbt/cross-platform.local"
|
||||
)
|
||||
|
||||
test("defaultTemplateDescriptions includes all built-in local template slugs"):
|
||||
val slugs = TemplateCommandUtil.defaultTemplateDescriptions.map(_._1)
|
||||
for slug <- localTemplateSlugs do
|
||||
assert(slugs.contains(slug), s"defaultTemplateDescriptions should contain '$slug'")
|
||||
|
||||
test("defaultRunLocalTemplate throws for unknown .local slug"):
|
||||
val log = Logger.Null
|
||||
val ex =
|
||||
try {
|
||||
TemplateCommandUtil.defaultRunLocalTemplate(List("unknown/template.local"), log)
|
||||
null
|
||||
} catch { case e: IllegalArgumentException => e }
|
||||
assert(ex ne null)
|
||||
assert(ex.getMessage.contains("Local template not found for:"))
|
||||
assert(ex.getMessage.contains("unknown/template.local"))
|
||||
|
|
@ -18,7 +18,7 @@ lazy val b = project
|
|||
classpathTypes += "test-jar",
|
||||
libraryDependencies ++= Seq(
|
||||
org %% nme % ver,
|
||||
org %% nme % ver % "test" classifier "tests"
|
||||
(org %% nme % ver % "test").classifier("tests")
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue