Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target/
/.bsp/
/pack/
/cli-test/
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inThisBuild(Def.settings(
organization := "org.scala-js",

crossScalaVersions := Seq("2.11.12", "2.12.15", "2.13.6"),
scalaVersion := crossScalaVersions.value.head,
scalaVersion := crossScalaVersions.value.last,
scalacOptions ++= Seq("-deprecation", "-feature", "-Xfatal-warnings"),

scalaJSVersion := "1.7.1",
Expand Down
35 changes: 24 additions & 11 deletions src/main/scala/org/scalajs/cli/Scalajsld.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ object Scalajsld {
logLevel: Level = Level.Info
)

private implicit object MainMethodRead extends scopt.Read[ModuleInitializer] {
val arity = 1
val reads = { (s: String) =>
val lastDot = s.lastIndexOf('.')
if (lastDot < 0)
throw new IllegalArgumentException(s"$s is not a valid main method")
ModuleInitializer.mainMethodWithArgs(s.substring(0, lastDot),
s.substring(lastDot + 1))
}
private def moduleInitializer(s: String, hasArgs: Boolean): ModuleInitializer = {
val lastDot = s.lastIndexOf('.')
if (lastDot < 0)
throw new IllegalArgumentException(s"$s is not a valid main method")
val className = s.substring(0, lastDot)
val mainMethodName = s.substring(lastDot + 1)
if (hasArgs)
ModuleInitializer.mainMethodWithArgs(className, mainMethodName)
else
ModuleInitializer.mainMethod(className, mainMethodName)
}

private implicit object ModuleKindRead extends scopt.Read[ModuleKind] {
Expand All @@ -85,12 +86,24 @@ object Scalajsld {
.unbounded()
.action { (x, c) => c.copy(cp = c.cp :+ x) }
.text("Entries of Scala.js classpath to link")
opt[ModuleInitializer]("mainMethod")
opt[String]("mainMethod")
.valueName("<full.name.Object.main>")
.abbr("mm")
.unbounded()
.action { (x, c) => c.copy(moduleInitializers = c.moduleInitializers :+ x) }
.action { (x, c) =>
val newModule = moduleInitializer(x, hasArgs = true)
c.copy(moduleInitializers = c.moduleInitializers :+ newModule)
}
.text("Execute the specified main(Array[String]) method on startup")
opt[String]("mainMethodWithNoArgs")
.valueName("<full.name.Object.main>")
.abbr("mma")
.unbounded()
.action { (x, c) =>
val newModule = moduleInitializer(x, hasArgs = false)
c.copy(moduleInitializers = c.moduleInitializers :+ newModule)
}
.text("Execute the specified main() method on startup")
opt[File]('o', "output")
.valueName("<file>")
.action { (x, c) => c.copy(output = Some(x)) }
Expand Down