Skip to content

Latest commit

 

History

History
83 lines (77 loc) · 3.85 KB

3-cli.md

File metadata and controls

83 lines (77 loc) · 3.85 KB
shortTitle shortDescription expandText anchorTarget icon
Command Line
Superpower your scripts with the Scala command. Get hands-on with the Scala Toolkit. Easily add libraries. Build CLI apps with instant startup.
Scripting Utilities
build-scala-tools
icon4.svg

The power of Scala in one file

Scala CLI gives all the tools you need to create simple Scala projects.

Import your favorite libraries, write your code, run it, create unit tests, share it as a gist, or publish it to Maven Central.

Scala CLI is fast, low-config, works with IDEs, and follows well-known conventions.

read more on the Scala CLI website
Create simple scripts and utilities with Scala CLI
//> using dependency com.lihaoyi::os-lib:0.9.1

// Sort all the files by size in the working directory os.list(os.pwd).sortBy(os.size).foreach(println)


$ scala-cli list_files.sc
/home/user/example/list_files.sc
...

Get productive with the Scala Toolkit

The Scala Toolkit is a good fit for writing a script, prototyping, or bootstrapping a new application.

Including a selection of approachable libraries to perform everyday tasks, the Scala Toolkit helps you work with files and processes, parse JSON, send HTTP requests and unit test code.

Toolkit libraries work great on the JVM, JS and Native platforms, all while leveraging a simple code style.

find useful snippets in the Toolkit Tutorials
Make web-requests, encode JSON and write to file
//> using toolkit latest

// A JSON object val json = ujson.Obj("name" -> "Peter", "age" -> 23)

// Send an HTTP request import sttp.client4.quick.* val response = quickRequest .put(uri"https://httpbin.org/put") .body(ujson.write(json)) .send()

// Write the response to a file os.write(os.pwd / "response.json", response.body)

Package to native, deploy easily

Package your apps to native binaries for instant startup time.

Deploy to Docker images, JS scripts, Spark or Hadoop jobs, and more.

other ways to package applications
Compile natively for instant startup
$ scala-cli --power package \
    --native-image \
    --output my-tool \
    my-tool.sc
Wrote /home/user/example/my-tool, run it with ./my-tool