Skip to content

Add a setting/API to run a code snippet/script in the REPL on startup #21242

@Gedochao

Description

@Gedochao

What needs to be done

We need a way to pass a code snippet or Scala source file that'd be run on REPL startup.
This is very similar to Ammonite REPL's (https://github.com/com-lihaoyi/Ammonite or --amm passed to Scala CLI) -c/--code option.

Why do we need this?

Requirements

I'd imagine we need:

  • a way to pass a code snippet or source file to the REPL main class to be executed at REPL startup
    • something like this:
    java
    -Dscala.usejavacp=true
    -classpath (...)
    dotty.tools.repl.Main
    -classpath (...)
    --init-script 'println("Hello from the init script in REPL")'
    # Welcome to Scala 3.4.2 (17, Java OpenJDK 64-Bit Server VM).
    # Type in expressions for evaluation. Or try :help.
    # 
    # Hello from the init script in REPL
    # scala> 
  • a way to skip the interactive mode and execute the script inside of the REPL, similar to what the -e flag does outside of the REPL
    • this would make testing integrations a lot easier
    • Ammonite equivalent:
    scala-cli repl --power --amm --ammonite-arg -c --ammonite-arg 'println("Hello from the init script in REPL")'
    # Compiling ~/Downloads/(console)
    # Hello from the init script in REPL

Context

Past discussions:

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions