Skip to content

Commit 9da63cf

Browse files
committed
Finished reviewing the Cookbook docs
1 parent 3f1d34a commit 9da63cf

File tree

7 files changed

+90
-79
lines changed

7 files changed

+90
-79
lines changed

website/docs/cookbooks/gists.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ title: Sharing and testing code with GitHub gists
33
sidebar_position: 6
44
---
55

6-
# Sharing and testing code with GitHub gists
7-
86
## Running code from gists
97

10-
`scala-cli` allows running Scala code straight from GitHub gists, without the need for manually downloading them first.
11-
This is done by just passing the link to a gist as an argument to `scala-cli`.
8+
`scala-cli` lets you run Scala code straight from GitHub gists, without the need to manually download them first.
9+
This is done by passing the link to a gist as an argument to `scala-cli`:
1210

13-
For example, having a given gist `https://gist.github.com/alexarchambault/7b4ec20c4033690dd750ffd601e540ec`:
11+
For example, given the gist `https://gist.github.com/alexarchambault/7b4ec20c4033690dd750ffd601e540ec`, which contains these two files:
1412
```scala title=Messages.scala
1513
object Messages {
1614
def hello = "Hello"
@@ -19,29 +17,31 @@ object Messages {
1917
```scala title=run.sc
2018
println(Messages.hello)
2119
```
22-
Running in terminal
20+
21+
You can run them with `scala-cli` like this:
2322
```bash
2423
scala-cli https://gist.github.com/alexarchambault/7b4ec20c4033690dd750ffd601e540ec
2524
```
2625
<!-- Expected:
2726
Hello
2827
-->
29-
Will print `Hello` to the standard output.
28+
29+
This example prints `Hello` to the standard output.
3030

3131
:::note
32-
Note that the gist doesn't necessarily have to be one file.
33-
`scala-cli` downloads the gist's archive and unzips it, so the gist can contain multiple files depending on each other.
32+
As shown in this example, the gist isn't limited to just one file.
33+
`scala-cli` downloads the gist's archive and unzips it, so the gist can contain multiple files that depend on each other.
3434

35-
`scala-cli` also caches the project sources using `coursier`'s cache.
35+
`scala-cli` also caches the project sources using Coursier's cache.
3636
:::
3737

3838
## Sharing code snippets
3939

4040
Together with the GitHub CLI (`gh`), it becomes really easy to share Scala code.
41+
If you want to share a code file named `file.scala`, just run this command to create the gist:
4142

42-
If you wants to share a code file, just run:
4343
```sh
4444
gh gist create file.scala
4545
```
4646

47-
And to run it quickly like shown above.
47+
Then you (and others) can run it quickly, using the `scala-cli` approach shown above.

website/docs/cookbooks/intro.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sidebar_position: 1
55

66
# Cookbook
77

8-
This part contains a set of recipes how to use scala-cli in certain situations. The cookbooks are intended to provide a solution to task at hand without providing too many details.
8+
This section of the documentation contains a set of recipes that show how to use `scala-cli` in certain situations.
9+
The recipes are intended to provide a solution to the task at hand, but also without going into great detail.
910

10-
For more in-depth analysis please check out provided [Guides](../guides/intro.md)
11+
For more in-depth analysis, please check out our [Guides](../guides/intro.md)

website/docs/cookbooks/scala-docker.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
---
2-
title: Package Scala application as a docker image
2+
title: Packaging Scala applications as Docker images
33
sidebar_position: 5
44
---
55

6-
# Package Scala application as a docker image
6+
Scala CLI can create an executable application and package it into a Docker image.
77

8-
ScalaCLI can create an executable application and package it into a docker image.
9-
10-
Here is a simple piece of code that will be executed in the docker container.
8+
For example, here's a simple piece of code that will be executed in a Docker container:
119

1210
```scala title=HelloDocker.scala
1311
object HelloDocker extends App {
1412
println("Hello from Docker")
1513
}
1614
```
1715

18-
Passing `--docker` to the `package` sub-command generates a docker image. The docker image name parameter `--docker-image-repository` is mandatory.
16+
Passing `--docker` to the `package` sub-command generates a Docker image. When creating a Docker image, the `--docker-image-repository` parameter is mandatory.
1917

20-
The following command will generate `hello-docker` image with `latest` tag:
18+
The following command generates a `hello-docker` image with the `latest` tag:
2119

2220
```bash
2321
scala-cli package --docker HelloDocker.scala --docker-image-repository hello-docker
@@ -38,7 +36,8 @@ docker run hello-docker
3836
Hello from Docker
3937
-->
4038

41-
It is also supported to package your app in `JS` or `Native` environments.
39+
You can also package your app in the Scala.JS or Scala Native environments.
40+
For example, this command creates a Scala.JS Docker image:
4241

4342
```bash
4443
scala-cli package --js --docker HelloDocker.scala --docker-image-repository hello-docker
@@ -49,8 +48,15 @@ Built docker image, run it with
4948
docker run hello-docker:latest
5049
-->
5150

52-
Package scala native application to docker image is supported only on Linux.
51+
This command creates a Scala Native Docker image:
5352

5453
```bash ignore
5554
scala-cli package --native --docker HelloDocker.scala --docker-image-repository hello-docker
5655
```
56+
57+
:::note
58+
Packaging a Scala Native application to a Docker image is supported only on Linux.
59+
:::
60+
61+
62+

website/docs/cookbooks/scala-jvm.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---
2-
title: Test your code with different Java versions
2+
title: Testing your code with different Java versions
33
sidebar_position: 4
44
---
55

6-
# Test your code with different Java versions
6+
You can use Scala CLI to test your code compatibility with various versions of `java`, with a key point being that manual installation of a JDK/SDK is not required(!).
7+
Scala CLI automatically downloads the Java version you specify.
78

8-
You can use Scala CLI to test your code compatibility with various versions of `java` (no manual installation of jdk or sdk is required). It automatically downloads the specified version of Java.
9-
10-
The following snippet uses the new method `Files.writeString` from Java 11.
9+
As an example, the following snippet uses the new method `Files.writeString` from Java 11:
1110

1211
```scala title=Main.scala
1312
import java.nio.file.Files
@@ -21,7 +20,7 @@ object Main extends App {
2120
}
2221
```
2322

24-
Pass `--jvm` to the `scala-cli` command to run your application with the specified java version.
23+
To use Java 11 to run this application, pass the following `--jvm` option to the `scala-cli` command:
2524

2625
```bash ignore
2726
scala-cli --jvm adopt:11 Main.scala
@@ -31,7 +30,7 @@ scala-cli --jvm adopt:11 Main.scala
3130
Hello from ScalaCli
3231
-->
3332

34-
To test your application with Java 8, change the value of `--jvm` parameter.
33+
To attempt to compile the application with Java 8, change the value of the `--jvm` parameter:
3534
```bash ignore fail
3635
scala-cli --jvm 8 Main.scala
3736
# In this case, it raises an error because the `Files.createTempFile` method is not available in java 8
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: Package Scala application as an executable file
2+
title: Packaging Scala applications as executable files
33
sidebar_position: 2
44
---
55

6-
Scala CLI allows you to package your application into a lightweight JAR file, that can be easily run.
7-
It only contains the byte code of your sources, and automatically downloads its dependencies on its first run.
6+
Scala CLI lets you package your application into a lightweight JAR file that can be easily run.
7+
The JAR file only contains the byte code that’s generated from your source code files, and automatically downloads its dependencies on its first run.
88

9-
The following snippet contains a short application to detect the OS:
9+
As an example, the following snippet contains a short application to detect the OS:
1010
```scala title=DetectOsApp.scala
1111
object DetectOSApp extends App {
1212
def getOperatingSystem(): String = {
@@ -19,7 +19,7 @@ object DetectOSApp extends App {
1919

2020
### Default format (lightweight launcher)
2121

22-
By default, the `package` sub-command generates a lightweight JAR.
22+
By default, the `package` sub-command generates a lightweight JAR that contains only your bytecode. This is how you create a lightweight JAR named `DetectOsApp.jar`:
2323

2424
```bash
2525
scala-cli package DetectOsApp.scala
@@ -30,37 +30,38 @@ Wrote DetectOsApp, run it with
3030
./DetectOsApp
3131
-->
3232

33-
Lightweight JARs require the `java` command to be available, and access to internet if dependencies need to be downloaded.
33+
Lightweight JARs require the `java` command to be available, and access to the internet, if dependencies need to be downloaded. This is how you run it on macOS:
3434

3535
```bash
36-
# Run DetectOsApp on MacOs
36+
# Run DetectOsApp on macOS
3737
./DetectOsApp
3838
# os: Mac OS X
3939
```
4040

41-
In the previous example, a Lightweight JAR that was built in a MacOs environment could also run on Linux.
41+
The lightweight JAR that was just built on macOS can also run on Linux:
4242

4343
```bash
4444
# Run DetectOsApp on Linux
4545
./DetectOsApp
4646
# os: Linux
4747
```
4848

49-
Scala-cli supports building Lightweight JARs in the MacOS, Linux, and Windows environments.
50-
JARs built on macOS and Linux are portable between these two OSs. The Lightweight JARs built on Windows can only be run on Windows.
49+
`scala-cli` supports building Lightweight JARs in the macOS, Linux, and Windows environments.
50+
JARs built on macOS and Linux are portable between these two operating systems.
51+
Lightweight JARs built on Windows can only be run on Windows.
5152

5253

5354
### Assemblies
54-
Passing `--assembly` to the `package` sub-command generates so-called "assemblies" or "fat JARs".
55+
Passing `--assembly` to the `package` sub-command generates so-called "assemblies," or "fat JARs":
5556

5657
```bash
5758
scala-cli package --assembly DetectOsApp.scala
5859
```
5960

60-
Assemblies also require the `java` command to be available in the `PATH`. As all dependencies are packaged into the assembly, nothing gets downloaded upon the first run and no internet access is required.
61+
Assemblies also require the `java` command to be available in the `PATH`. But in this case, all of the dependencies that are needed are packaged into the assembly, so nothing gets downloaded upon the first run, and no internet access is required.
6162

6263
```bash
63-
# Run DetectOsApp on MacOs
64+
# Run DetectOsApp on macOS
6465
./DetectOsApp
6566
# os: Mac OS X
6667
```

website/docs/cookbooks/scala-scripts.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
---
2-
title: Use scala-cli to run Scala Scripts
2+
title: Using scala-cli to run Scala Scripts
33
sidebar_position: 3
44
---
55

66
## Scala Scripts
77

8-
Scala Scripts are files containing Scala code without main method required. These codes of Scala do not require build-tools configurations. To run Scala Scripts very quickly without waiting for warn-up build-tools, you can use `scala-cli`.
8+
Scala scripts are files that contain Scala code without a main method.
9+
These source code files don't require build-tool configurations.
10+
To run Scala scripts very quickly without waiting the need for build tools, use `scala-cli`.
911

1012
### Run
1113

12-
You can use `scala-cli` to run Scala scripts (no further setup is required):
14+
For example, given this simple script:
1315

1416
```scala title=HelloScript.sc
1517
val sv = scala.util.Properties.versionNumberString
@@ -18,6 +20,8 @@ val message = s"Hello from Scala ${sv}, Java ${System.getProperty("java.version"
1820
println(message)
1921
```
2022

23+
You can run it directly with `scala-cli` — there's no need for a build tool or additional configuration:
24+
2125
```bash
2226
scala-cli run HelloScript.sc
2327
```
@@ -26,8 +30,7 @@ scala-cli run HelloScript.sc
2630
Hello from Scala .*, Java .*
2731
-->
2832

29-
30-
Alternatively, add a "shebang" header to your script, make your script executable, and execute it directly. `scala-cli` needs to be installed for this to work.
33+
Alternatively, you can add a "shebang" header to your script, make it executable, and execute it directly with `scala-cli`. For example, given this script with a header that invokes `scala-cli`:
3134

3235
```scala title=HelloScriptSheBang.sc
3336
#!/usr/bin/env scala-cli
@@ -41,6 +44,7 @@ def printMessage(): Unit =
4144
printMessage()
4245
```
4346

47+
You can make it executable and then run it like this:
4448

4549
```bash
4650
chmod +x HelloScriptSheBang.sc
@@ -52,7 +56,7 @@ chmod +x HelloScriptSheBang.sc
5256
Hello from Scala .*, Java .*
5357
-->
5458

55-
It is also possible to pass command-line arguments to the script
59+
You can also pass command line arguments to Scala scripts:
5660

5761
```scala title=ScriptArguments.sc
5862
#!/usr/bin/env scala-cli
@@ -69,14 +73,16 @@ chmod +x ScriptArguments.sc
6973
bar
7074
-->
7175

76+
As shown, command line arguments are accessed through the special `args` variable.
77+
7278

7379
## Features
7480

75-
All the features from non-scripts work for Scala scripts too, such as waiting for changes (watch mode), dependencies menagement, packaging, compiling and many others.
81+
All of the features shown for non-scripts work for Scala scripts as well, such as waiting for changes (watch mode), dependency menagement, packaging, compiling, etc.
7682

7783
### Package
7884

79-
Run `package` to the Scala CLI to package your script to a lightweight executable JAR file.
85+
For example, run the `package` sub-command to package your script as a lightweight executable JAR file:
8086

8187
```bash
8288
scala-cli package HelloScript.sc
@@ -89,7 +95,7 @@ Hello from Scala .*, Java .*
8995

9096
### Watch mode
9197

92-
Pass `--watch` to the Scala CLI to watch all sources for changes, and re-run them upon changes.
98+
As another example, pass `--watch` to `scala-cli` to watch all source files for changes, and then re-run them when there is a change:
9399

94100
```bash ignore
95101
scala-cli --watch HelloScript.sc

0 commit comments

Comments
 (0)