I have a large number of simple Scala command-line applications that share a fairly general structure. They all inherit from scala.App, which is just fine. I would like to reorganize the general structure of these command-line applications into a common feature, which I could then inherit in my (much simpler) classes of command-line applications. The problem is that some of the general structure includes parsing command line arguments.
object MyScript extends BaseScript with App{ //small bits of business logic using components defined in BaseScript } trait BaseScript extends App{ val configuration = loadConfiguration(args(0)) //setup a bezillion components, usable from any of the scripts, based on the configuration }
This compiles, but does not work with NPE when it comes time to actually dereference args
, apparently because the App
flag has not yet been initialized. Changing character orders and changing the inheritance of an App in BaseScript as a self-supporting declaration do nothing, just like experimenting with DelayedInit. Declaring components as “lazy” in BaseScript will work, but I also need to use these components during initialization (for example, setting up log directories and loading JDBC driver classes based on configuration), so the benefits of laziness are lost. Is there something I can do to make the command line arguments visible and initialized in a BaseScript value?
source share