I am trying to write a ammonite script which triggers an SBT task.
So far this is what I have written.
test.sh
#!/usr/bin/env amm
import sys.process._
import java.io.File
import ammonite.ops._, ImplicitWd._
@main
def ini(args: String*) = {
val server = args.headOption.getOrElse("devserver")
val path = /'Users/'Foo/'IdeaProjects/'my-project
val process = Process(Seq("sbt", "clean"), path)
process.!
}
I am having multiple problems here
instead of using the
Process
object I want to use the ammnoite%
to launch the process. But then how do I set the working directory for the process being launched?From the command line I run my code like
sbt "runmain com.test.Foo 1 2 3"
. When calling the process from%
how can I correctly call runMain with all the parameters?
Do this:
%.sbt('runmain,"com.test.foo",arg1,arg2,arg3)(path)
Where path is the directory you want it performed in & the args are explicitly named, not arg*. It's Scala so you can preset values for arts & you can used named arguments by prefixing the name w/
--'
Another alternative is to write a shell script to first cd to the directory & then run the ammonite script with parameters.