Is there a good library for embedding the command line in a scala (or java) application

I have an application to which I would like to receive an invitation. If this helps, this is the implementation of the graph database, and I need a hint, like any other database client (MySQL, Postgresql, etc.).

So far I have my own REPL:

object App extends Application {
    REPL ! Read
}

object REPL extends Actor {
    def act() {
        loop {
            react {
                case Read => {
                    print("prompt> ")
                    var message = Console.readLine
                    this ! Eval(message)
                }
                case More(sofar) => {
                    //Eval didn't see a semicolon
                    print("    --> ")
                    var message = Console.readLine
                    this ! Eval(sofar + " " + message)
                }
                case Eval(message) => {
                    Evaluator ! Eval(message)
                }
                case Print(message) => {
                    println(message)
                    //And here the loop
                    this ! Read
                }
                case Exit => {
                    exit()
                }
                case _ => {
                    println("App: How did we get here")
                }
            }
        }
    }
    this.start
}

It works, but I would really like to have something with the story. Tab filling is not required.

Any suggestions for a good library? Scala or running Java.

Just to be clear, I don't need a REPL to evaluate my code (I get this with scala!), And I'm not going to call or use anything from the command line. I am looking for a hint which is my user interface when starting my client application.

+3
3

Scala readline-like library REPL. , JLine.

, .

+6

. .

http://danielwestheide.com/blog/2013/01/09/the-neophytes-guide-to-scala-part-8-welcome-to-the-future.html

http://danielwestheide.com/blog/2013/01/16/the-neophytes-guide-to-scala-part-9-promises-and-futures-in-practice.html

def interprete(code: String) : Future[String] = {
val p = Promise[String]()

Future {
  var result = reader.readLine()
  p.success(result)
}

writer.write(code + "\n")
writer.flush()

p.future

}

for (ln <- io.Source.stdin.getLines){
  val f = interprete(ln)
  f.onComplete {
    case Success(s) =>
      println("future returned: " + s)
    case Failure(ex) =>
      println(s"interpreter failed due to ${ex.getMessage}")
  }

}
0

Source: https://habr.com/ru/post/1772218/


All Articles