-
-
Notifications
You must be signed in to change notification settings - Fork 317
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
Commands parameter parser should support delegate classes #1877
Comments
@lihaoyi Could you comment whether this is already possible or how much work this might take in either mainargs or Mill? |
To really avoid binary compatibility issue, case classes are a bad choice. We rather want to use ordinary classes, so we probably need to add support for these in |
Haha, this is actually working, when not defined in a trait MyModule extends Module {
def argTest(args: MyModule.MyArgs) = T.command {
println(s"args: ${args}")
}
}
object MyModule {
case class MyArgs(a: mainargs.Flag = mainargs.Flag(false), b: Seq[String] = Seq.empty[String])
implicit val argsReader: mainargs.ParserForClass[MyArgs] = mainargs.ParserForClass[MyArgs]
} It's even working for non-case classes, as long as we provide a companion object with an apply method. trait MyModule extends Module {
def argTest(args: MyModule.MyArgs) = T.command {
println(s"args: ${args}")
}
}
object MyModule {
class MyArgs private (val a: mainargs.Flag, val b: Seq[String]) {
override def toString: String = getClass.getSimpleName + ("a=" + a + ",b=" + b + ")")
}
object MyArgs {
@deprecated("test deprecation")
def apply(a: mainargs.Flag): MyArgs = apply(a, Seq.empty)
def apply(a: mainargs.Flag = mainargs.Flag(false), b: Seq[String] = Seq.empty): MyArgs =
new MyArgs(a, b)
}
implicit val argsReader: mainargs.ParserForClass[MyArgs] = mainargs.ParserForClass[MyArgs]
} |
Because the way commands are currently implemented, there is no well defined way to overload a command with different options. This makes gradual evolving a modules API hard.
mainargs
already supports parsing case classes. If Mill would support parsing of command parameter by delegating to parsing a case class first, we could gradually evolve and deprecate some parameters without breaking (binary) compatibility.Example:
The text was updated successfully, but these errors were encountered: