-
-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to alias Modules (specially external modules) #299
Comments
As a workaround, something like this can be added to the if [ "$1" = "bloop" ] ; then
exec $MILL_EXEC_PATH mill.contrib.Bloop/install
elif [ "$1" = "idea" ] ; then
exec $MILL_EXEC_PATH mill.scalalib.GenIdea/idea
else
exec $MILL_EXEC_PATH "$@"
fi A bit better than global shell alias. |
I have an implementation I add to all my // In your build.sc
...
// -----------------------------------------------------------------------------
// Command Aliases
// -----------------------------------------------------------------------------
// Alias commands are run like `./mill run [alias]`
// Define the alias as a map element containing the alias name and a Seq with the tasks to be executed
val aliases: Map[String, Seq[String]] = Map(
"lint" -> Seq("mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources", "__.fix"),
"fmt" -> Seq("mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources"),
"checkfmt" -> Seq("mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources"),
"deps" -> Seq("mill.scalalib.Dependency/showUpdates"),
"testall" -> Seq("__.test"),
"pub" -> Seq("io.kipp.mill.ci.release.ReleaseModule/publishAll"),
)
// Alias Runner
def run(ev: eval.Evaluator, alias: String = "") = T.command {
aliases.get(alias) match {
case Some(t) =>
mill.main.MainModule.evaluateTasks(
ev,
t.flatMap(x => Seq(x, "+")).flatMap(_.split("\\s+")).init,
mill.define.SelectMode.Single,
)(identity)
case None =>
Console.err.println("Use './mill run [alias]'."); Console.out.println("Available aliases:")
aliases.foreach(x => Console.out.println(s"${x._1.padTo(15, ' ')} - Commands: (${x._2.mkString(", ")})"));
sys.exit(1)
}
} For example: ❯ ./mill run
[1/1] run
Use './mill run [alias]'.
Available aliases:
testall - Commands: (__.test)
pub - Commands: (io.kipp.mill.ci.release.ReleaseModule/publishAll)
deps - Commands: (mill.scalalib.Dependency/showUpdates)
fmt - Commands: (mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources)
lint - Commands: (mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources, __.fix)
checkfmt - Commands: (mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources)
❯ ./mill run fmt
[1/1] run > [7/7] mill.scalalib.scalafmt.ScalafmtModule.reformatAll
Formatting 2 Scala sources
parsed config (v3.7.3): /Users/cdepaula/repos/scala/mill-docker-nativeimage/.scalafmt.conf I could submit a PR adding something like this to the core Mill if desired. |
Nice that this is "built-in" and documented but just a heads-up that my plugin(https://github.com/carlosedp/mill-aliases) allows one to define an alias that calls a sequence of other modules or commands. |
In the spirit of issue 259, wouldn't it be nice to give Mill the capability to alias commands and/or (external?) modules?
So if someone working creating an External Module with a long package name can therefore call an easy to remember alias than the whole package name plus slash plus target.
The text was updated successfully, but these errors were encountered: