Last active
December 17, 2015 11:20
-
-
Save frgomes/93bbd166f256d18abe7f to your computer and use it in GitHub Desktop.
Scala script - template script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#-*- mode: scala; -*- | |
##### | |
##### NOTE: save this script WITHOUT EXTENSION onto the file system. | |
##### | |
launcher=$(which sbt-launch.jar) | |
if [ -z "$launcher" ] ;then | |
pushd /tmp | |
if [ ! -f sbt-launch.jar ] ;then | |
wget http://dl.bintray.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.9/sbt-launch.jar | |
fi | |
popd | |
launcher=/tmp/sbt-launch.jar | |
fi | |
exec java \ | |
-Dsbt.main.class=sbt.ScriptMain \ | |
-Dsbt.boot.directory=${HOME}/.sbt/boot \ | |
-Dsbt.log.noformat=true \ | |
-jar ${launcher} --error "$0" "+ $*" # see: https://github.com/sbt/sbt/issues/2257 | |
!# | |
/*** | |
scalaVersion := "2.11.7" | |
resolvers ++= | |
Seq( | |
//XXX Resolver.file("Local Ivy", file(Path.userHome.absolutePath + "/.ivy2/local"))(Resolver.ivyStylePatterns), | |
Resolver.jcenterRepo) | |
libraryDependencies ++= | |
Seq( | |
"org.mongodb" %% s"casbah-core" % s"2.7.4") | |
*/ | |
import com.mongodb.casbah.Imports._ | |
trait Runner { | |
val dbServerNames : String | |
val databaseName : String | |
val collectionName : String | |
def exec(os: java.io.OutputStream): Int = { | |
val pw = new java.io.PrintWriter(os) | |
pw.write(s"${dbServerNames}\n") | |
pw.write(s"${databaseName}\n") | |
pw.write(s"${collectionName}\n") | |
pw.flush | |
recs | |
} | |
} | |
val runner = new { | |
val dbServerNames : String = "localhost" | |
val databaseName : String = "db" | |
val collectionName : String = "collection" | |
} with Runner | |
import java.io._ | |
val os = | |
(args diff Seq("+")).headOption match { | |
case Some(name) => new FileOutputStream(new File(name)) | |
case _ => System.out | |
} | |
runner.exec(os) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment