scalacommand-linescopt

Combining CommandLine Option Parsers with Scopt


I am currently using scopt for a Command Line Application. However My scopt.OptionParser[Config] is getting very large. I was thinking it might be nice to break it into smaller parts, and then combine them.

After reading the documentation I don't see any way of doing that.

Did I miss something? Or is it not possible?


Solution

  • Yes it can be broken into smaller chunks. You can do it by moving functionality into traits something like:

    trait FooParser { self: OptionParser[MyArgs] =>
      cmd("foo")
      ...
    }
    trait BarParser { self: OptionParser[MyArgs] =>
      cmd("bar")
      ...
    }
    val fooBarParser = new OptionParser[MyArgs]("FooBar") with FooParser with BarParser {
      head("FooBar")
      ...
    }