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

Putting @main in a mixin #145

Open
kincsescsaba opened this issue Aug 7, 2024 Discussed in #144 · 0 comments
Open

Putting @main in a mixin #145

kincsescsaba opened this issue Aug 7, 2024 Discussed in #144 · 0 comments

Comments

@kincsescsaba
Copy link

Discussed in #144

Originally posted by kincsescsaba August 7, 2024
Hey there,

I'm not sure if this is an issue or more like a feature request, but when I try to place the @main annotation of mainargs in a trait, that is mixed into the class that contains the main method, I get a No @main methods declared error.

I tried referencing the self type from ParserForMethods but that did not fix the issue.

Here's how the approach looks like:

abstract class CaskMainWithArgs extends cask.Main:
  self: Conf =>
  private var args_ : Seq[String] = uninitialized
  def args: Seq[String] = args_
  
  override def main(argsArray: Array[String]): Unit =
    if Option(args_).isEmpty then
      args_ = argsArray.toSeq
      ParserForMethods(self).runOrExit(argsArray)
      super.main(argsArray)

trait Conf:
  self: CaskMainWithArgs =>

  @main
  def runConfInit(@arg(name = "conf", short = 'c', doc = "Set a custom configuration file")
                  configFile: String) =
    println("Hello from runConfInit")

Any ideas on how this behavior could be implemented?

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

1 participant