Skip to content

Commit

Permalink
Mark reformatAll/checkReformatAll/runMain arguments as position…
Browse files Browse the repository at this point in the history
…al (#3455)

These are commands that probably do not expect named params that I found
in a cursory audit, that would otherwise be broken by
#3431. We can annotate others as
we find them
  • Loading branch information
lihaoyi authored Sep 3, 2024
1 parent 87d6ced commit 9a9d928
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
14 changes: 9 additions & 5 deletions scalajslib/src/mill/scalajslib/ScalaJSModule.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mill
package scalajslib

import mainargs.Flag
import mainargs.{Flag, arg}
import mill.api.{Loose, PathRef, Result, internal}
import mill.scalalib.api.ZincWorkerUtil
import mill.scalalib.Lib.resolveDependencies
Expand Down Expand Up @@ -163,13 +163,17 @@ trait ScalaJSModule extends scalalib.ScalaModule { outer =>

}

override def runMainLocal(mainClass: String, args: String*): Command[Unit] = T.command[Unit] {
override def runMainLocal(
@arg(positional = true) mainClass: String,
args: String*
): Command[Unit] = T.command[Unit] {
mill.api.Result.Failure("runMain is not supported in Scala.js")
}

override def runMain(mainClass: String, args: String*): Command[Unit] = T.command[Unit] {
mill.api.Result.Failure("runMain is not supported in Scala.js")
}
override def runMain(@arg(positional = true) mainClass: String, args: String*): Command[Unit] =
T.command[Unit] {
mill.api.Result.Failure("runMain is not supported in Scala.js")
}

private[scalajslib] def linkJs(
worker: ScalaJSWorker,
Expand Down
14 changes: 10 additions & 4 deletions scalalib/src/mill/scalalib/JavaModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import coursier.core.Resolution
import coursier.parse.JavaOrScalaModule
import coursier.parse.ModuleParser
import coursier.util.ModuleMatcher
import mainargs.Flag
import mainargs.{Flag, arg}
import mill.Agg
import mill.api.{Ctx, JarManifest, MillException, PathRef, Result, internal}
import mill.define.{Command, ModuleRef, Segment, Task, TaskModule}
Expand Down Expand Up @@ -950,23 +950,29 @@ trait JavaModule
/**
* Same as `runBackground`, but lets you specify a main class to run
*/
override def runMainBackground(mainClass: String, args: String*): Command[Unit] = {
override def runMainBackground(
@arg(positional = true) mainClass: String,
args: String*
): Command[Unit] = {
// overridden here for binary compatibility (0.11.x)
super.runMainBackground(mainClass, args: _*)
}

/**
* Same as `runLocal`, but lets you specify a main class to run
*/
override def runMainLocal(mainClass: String, args: String*): Command[Unit] = {
override def runMainLocal(
@arg(positional = true) mainClass: String,
args: String*
): Command[Unit] = {
// overridden here for binary compatibility (0.11.x)
super.runMainLocal(mainClass, args: _*)
}

/**
* Same as `run`, but lets you specify a main class to run
*/
override def runMain(mainClass: String, args: String*): Command[Unit] = {
override def runMain(@arg(positional = true) mainClass: String, args: String*): Command[Unit] = {
// overridden here for binary compatibility (0.11.x)
super.runMain(mainClass, args: _*)
}
Expand Down
7 changes: 4 additions & 3 deletions scalalib/src/mill/scalalib/RunModule.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mill.scalalib

import mainargs.arg
import mill.api.JsonFormatters.pathReadWrite
import mill.api.{Ctx, PathRef, Result}
import mill.define.{Command, Task}
Expand Down Expand Up @@ -95,23 +96,23 @@ trait RunModule extends WithZincWorker {
/**
* Same as `run`, but lets you specify a main class to run
*/
def runMain(mainClass: String, args: String*): Command[Unit] = {
def runMain(@arg(positional = true) mainClass: String, args: String*): Command[Unit] = {
val task = runForkedTask(T.task { mainClass }, T.task { Args(args) })
T.command { task }
}

/**
* Same as `runBackground`, but lets you specify a main class to run
*/
def runMainBackground(mainClass: String, args: String*): Command[Unit] = {
def runMainBackground(@arg(positional = true) mainClass: String, args: String*): Command[Unit] = {
val task = runBackgroundTask(T.task { mainClass }, T.task { Args(args) })
T.command { task }
}

/**
* Same as `runLocal`, but lets you specify a main class to run
*/
def runMainLocal(mainClass: String, args: String*): Command[Unit] = {
def runMainLocal(@arg(positional = true) mainClass: String, args: String*): Command[Unit] = {
val task = runLocalTask(T.task { mainClass }, T.task { Args(args) })
T.command { task }
}
Expand Down
6 changes: 4 additions & 2 deletions scalalib/src/mill/scalalib/scalafmt/ScalafmtModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import mill.main.client.CodeGenConstants.buildFileExtensions
import mill.api.Result
import mill.define.{ExternalModule, Discover}
import mill.scalalib._
import mainargs.arg

trait ScalafmtModule extends JavaModule {

Expand Down Expand Up @@ -69,7 +70,7 @@ trait ScalafmtModule extends JavaModule {

object ScalafmtModule extends ExternalModule with ScalafmtModule {

def reformatAll(sources: mill.main.Tasks[Seq[PathRef]]): Command[Unit] =
def reformatAll(@arg(positional = true) sources: mill.main.Tasks[Seq[PathRef]]): Command[Unit] =
T.command {
val files = T.sequence(sources.value)().flatMap(filesToFormat)
ScalafmtWorkerModule
Expand All @@ -80,7 +81,8 @@ object ScalafmtModule extends ExternalModule with ScalafmtModule {
)
}

def checkFormatAll(sources: mill.main.Tasks[Seq[PathRef]]): Command[Unit] =
def checkFormatAll(@arg(positional = true) sources: mill.main.Tasks[Seq[PathRef]])
: Command[Unit] =
T.command {
val files = T.sequence(sources.value)().flatMap(filesToFormat)
ScalafmtWorkerModule
Expand Down

0 comments on commit 9a9d928

Please sign in to comment.