Skip to main content

Commands

This document describes as scala-cli behaves if run as scala command. See more information in SIP-46

scala commands

This document is a specification of scala runner. For now it uses documentation specific to Scala CLI but at some point it may be refactor to provide more abstract documentation. Documentation is splitted into sections in the spirit of RFC keywords (MUST, SHOULD, NICE TO HAVE) including IMPLEMENTATION category, that is reserved for commands that needs to be present for Scala CLI to work properly but should not be a part of an official API.

MUST have commands:

compile

Compile Scala code

Accepts option groups: compilation server, compile, coursier, cross, debug, dependency, directories, help group, input, jvm, logging, markdown, Scala.js, Scala Native, scalac, scalac extra, shared, snippet, verbosity, watch, workspace

doc

Generate Scaladoc documentation

Accepts option groups: compilation server, coursier, debug, dependency, directories, doc, help group, input, jvm, logging, markdown, Scala.js, Scala Native, scalac, scalac extra, shared, snippet, verbosity, workspace

help

Print help message

repl

Aliases: console

Fire-up a Scala REPL

Accepts option groups: compilation server, coursier, cross, debug, dependency, directories, help group, input, java, jvm, logging, markdown, python, repl, Scala.js, Scala Native, scalac, scalac extra, shared, snippet, verbosity, watch, workspace

run

Compile and run Scala code.

To pass arguments to the application, just add them after --, like:

scala-cli MyApp.scala -- first-arg second-arg

Accepts option groups: benchmarking, compilation server, coursier, cross, debug, dependency, directories, help group, input, java, jvm, logging, main class, markdown, python, run, Scala.js, Scala Native, scalac, scalac extra, shared, snippet, verbosity, watch, workspace

SHOULD have commands:

about

Print details about this application

Accepts option groups: about, verbosity

fmt

Aliases: format, scalafmt

Format Scala code

Accepts option groups: compilation server, coursier, debug, dependency, directories, fmt, help group, input, jvm, logging, markdown, Scala.js, Scala Native, scalac, scalac extra, shared, snippet, verbosity, workspace

shebang

Like run, but more handy from shebang scripts

This command is equivalent to run, but it changes the way scala-cli parses its command-line arguments in order to be compatible with shebang scripts.

Normally, inputs and scala-cli options can be mixed. Program have to be specified after --

scala-cli [command] [scala_cli_options | input]... -- [program_arguments]...

Contrary, for shebang command, only a single input file can be set, all scala-cli options have to be set before the input file, and program arguments after the input file

scala-cli shebang [scala_cli_options]... input [program_arguments]...

Using this, it is possible to conveniently set up Unix shebang scripts. For example:

#!/usr/bin/env -S scala-cli shebang --scala-version 2.13
println("Hello, world)

Accepts option groups: benchmarking, compilation server, coursier, cross, debug, dependency, directories, help group, input, java, jvm, logging, main class, markdown, python, run, Scala.js, Scala Native, scalac, scalac extra, shared, snippet, verbosity, watch, workspace

test

Compile and test Scala code

Accepts option groups: compilation server, coursier, cross, debug, dependency, directories, help group, input, java, jvm, logging, markdown, Scala.js, Scala Native, scalac, scalac extra, shared, snippet, test, verbosity, watch, workspace

version

Print scala-cli version

Accepts option groups: verbosity, version

Implementation-specific commands

Commands that are used within Scala CLI that should be a part of the scala command but shouldn't be a part of specification.

bsp

Start BSP server

Accepts option groups: bsp, compilation server, coursier, debug, dependency, directories, help group, input, jvm, logging, markdown, Scala.js, Scala Native, scalac, scalac extra, shared, snippet, verbosity, workspace

clean

Clean the workspace

Accepts option groups: bsp file, directories, logging, verbosity, workspace

doctor

Print details about this application

Accepts option groups: doctor, verbosity

install completions

Aliases: install-completions

Installs completions into your shell

Accepts option groups: directories, install completions, logging, verbosity

install-home

Install scala-cli in a sub-directory of the home directory

Accepts option groups: install home, verbosity

setup-ide

Generate a BSP file that you can import into your IDE

Accepts option groups: bsp file, compilation server, coursier, debug, dependency, directories, help group, input, jvm, logging, markdown, Scala.js, Scala Native, scalac, scalac extra, setup IDE, shared, snippet, verbosity, workspace

uninstall

Uninstall scala-cli - only works when installed by the installation script

Accepts option groups: compilation server, coursier, directories, logging, uninstall, uninstall completions, verbosity

uninstall completions

Aliases: uninstall-completions

Uninstalls completions from your shell

Accepts option groups: logging, uninstall completions, verbosity

update

Update scala-cli - only works when installed by the installation script

Accepts option groups: update, verbosity