Skip to content
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

Support main methods from traits #89

Open
UnaiUribarri-TomTom opened this issue Aug 10, 2023 · 1 comment
Open

Support main methods from traits #89

UnaiUribarri-TomTom opened this issue Aug 10, 2023 · 1 comment

Comments

@UnaiUribarri-TomTom
Copy link

UnaiUribarri-TomTom commented Aug 10, 2023

My Main object has grown too large and I want to split it. I tried to create a trait for each entry point and then making the Main object extends all those traits. But in such case, mainargs does not find any of the @main annotated entry points in any of the traits, while it worked flawlessly when all those methods were together in the same Main object.

trait CommandList {
  @main
  def list(@arg v: String): Unit = ???
}

trait CommandCopy {
  @main
  def copy(@arg from: String, @arg to: String): Unit = ???
}

object Main extends CommandList with CommandCopy {
  def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args)
}

Is there any way to support this use case? Without having to duplicate the entry point in all of them, of course.

@lihaoyi
Copy link
Member

lihaoyi commented Aug 10, 2023

This seems reasonable. I thought it would work already, but I've never tried and I guess if you're opening this ticket it doesn't. Should be implementable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants