Victor Garbuz
Victor Garbuz

Reputation: 85

How to pass arguments to scala file in the sbt console?

cat test.scala

println("Hello, " + args(0) + "!")

I've found that for loading file there is :load command but how can I pass arguments to script? I'm using sbt console

Upvotes: 0

Views: 443

Answers (1)

FlorianK
FlorianK

Reputation: 440

As far as I understand it, this is not something you can do in the sbt console. You can run your file as a script with:

scala test.scala

If you want to load it in the sbt console I think you have to make a function of your code and wrap it in an object, because otherwise it will not compile:

object TestProgram {
    def greet(name: String) = println("Hello, " + name)
}

which you can then call from sbt console with TestProgram.greet("world")

Upvotes: 1

Related Questions