Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
Gedochao opened this issue Jul 22, 2024 · 0 comments · May be fixed by #22206
Open
2 tasks

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

Gedochao opened this issue Jul 22, 2024 · 0 comments · May be fixed by #22206

Comments

@Gedochao
Copy link
Contributor

Gedochao commented Jul 22, 2024

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants