//import com.tapad.dfe.config.{Configuration, ClasspathConfigResolver} //import com.typesafe.config.{ConfigValueFactory, ConfigFactory, Config} import com.typesafe.scalalogging.slf4j.Logging //import java.io.File //import org.rogach.scallop.ScallopConf //import scala.util.{Failure, Success, Try} object Runner extends Logging { def main(args: Array[String]) = { // parse command line args val opts = new ScallopConf(List("-h")) { version("1.0") banner(""" Delivery File Uploader runner Example: java -jar dfe.jar [--config path/to/config/file] java -jar dfe.jar [-c path/to/config/file] java -Dcom.tapad.dfe.env=test -jar dfe.jar For options see below: """) val config = opt[String]("config", descr = """ Provide the path to the configuration file, if the option is omitted, then | the configuration will be loaded from the classpath, depending on your | environment, hence the file 'dfe-${ENV}.conf' will be used. | |To define environment (in priority order) | * "default" (lowest priority) | * TAPAD_ENV environment variable | * the first file with *.env in the current dir (it's content doesn't matter) | * "com.tapad.dfe.env" system property | """.stripMargin) val version = opt[Boolean]("version", descr = "Print version") val help = opt[Boolean]("help", descr = "Show this message") } try { // try to load the config, and assign it to the Configuration println(Configuration.conf) val config = opts.config val path = config.apply() val file = new File(path) if (!file.exists()) { throw new Exception(s"The configuration file $path does not exist") } val ref = ConfigValueFactory.fromAnyRef(file.getAbsolutePath) Configuration.conf = Configuration.loadConf( ConfigFactory.parseFile(file).withValue("source", ref) ) } catch { case err: Throwable => logger.error(err.getMessage) } } }