Skip to content

Commit 5848d09

Browse files
authored
Merge pull request #277 from alvinj/aa-docs-review
Initial edits to Overview and Commands
2 parents ea7ab3e + 582d8ab commit 5848d09

File tree

12 files changed

+210
-194
lines changed

12 files changed

+210
-194
lines changed

website/docs/commands/basics.md

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,40 @@ title: Basics
33
sidebar_position: 3
44
---
55

6-
Scala CLI is a command line tool that executes a given command on provided inputs with given [configuration](../guides/configuration.md) to produce a result. Most important commands are:
6+
Scala CLI is a command line tool that executes a given command on the inputs it’s provided with a given [configuration](../guides/configuration.md) to produce a result.
77

8-
- [compile](./compile.md) to compile you code (this exclude tests)
9-
- [run](./run.md) - to run your code using provided arguments (also used when no other command is provided)
10-
- [test](./test.md) - to compile and run tests defined in your code
11-
- [package](./package.md) - to package your code into a jar or other format
12-
- [repl](./repl.md) / [console](./repl.md) - to run interactive Scala shell
13-
- [fmt](./fmt.md) - to format your code
8+
The most important commands are:
149

15-
If Scala CLI is run without any command provided, it will default to the `run` command, so `scala-cli a.scala` will run your `a.scala` file.
10+
- [compile](./compile.md) compiles your code (excluding tests)
11+
- [run](./run.md) runs your code using the provided arguments (it’s also used when no other command is provided)
12+
- [test](./test.md) compiles and runs the tests defined in your code
13+
- [package](./package.md) packages your code into a jar or other format
14+
- [repl](./repl.md) / [console](./repl.md) runs the interactive Scala shell
15+
- [fmt](./fmt.md) formats your code
16+
17+
When Scala CLI is run without any commands, it defaults to the `run` command, so <br/>`scala-cli a.scala` runs your `a.scala` file.
1618

1719
## Input formats
1820

1921
The `scala-cli` CLI commands accept input in a number of ways, most notably:
22+
2023
- as source files
21-
- as one or several directories, containing sources
24+
- as one or several directories that contain source files
2225
- as URLs, pointing to sources
23-
- by piping or process substitution source code directly
26+
- by processing source code via piping or process substitution
2427

25-
Lastly, note that all these input formats can used alongside each other.
28+
Note that all of these input formats can used alongside each other.
2629

2730
## Source files
2831

29-
Scala CLI accepts following kinds of source:
30-
- `.scala` files containing Scala code
31-
- `.sc` files, containing Scala scripts (see more in [Scripts guide](../guides/scripts.md))
32-
- `.java` files containing Java code
32+
Scala CLI accepts the following types of source code:
3333

34-
This is the simplest input format. Just write a source file, and pass it to
35-
`scala-cli` to run it:
34+
- `.scala` files, containing Scala code
35+
- `.sc` files, containing Scala scripts (see more in [Scripts guide](../guides/scripts.md))
36+
- `.java` files, containing Java code
37+
38+
This example shows the simplest input format.
39+
First, create a source file:
3640

3741
```scala title=Hello.scala
3842
object Hello {
@@ -41,13 +45,14 @@ object Hello {
4145
}
4246
```
4347

44-
Run it with
48+
The run it by passing it to `scala-cli`:
49+
4550
```bash
4651
scala-cli Hello.scala
4752
# Hello from Scala
4853
```
4954

50-
You can also split your code in multiple files, and pass all of them to `scala-cli` :
55+
You can also split your code into multiple files:
5156

5257
```scala title=Messages.scala
5358
object Messages {
@@ -62,30 +67,33 @@ object Hello {
6267
}
6368
```
6469

65-
Run them with
70+
and the run them with `scala-cli`:
71+
6672
```bash
6773
scala-cli Hello.scala Messages.scala
6874
# Hello from Scala
6975
```
7076

7177
:::note
72-
Scala CLI compiles together only the provided inputs.
73-
:::
74-
75-
If we provide only one of the files above:
78+
Scala CLI compiles only the provided inputs.
79+
For example, if we provide only one of the files above:
7680

7781
```bash fail
7882
scala-cli Hello.scala
7983
```
8084

81-
compilation will fail even though a moment ago files compiled together without any problem.
85+
compilation will fail. `scala-cli` compiles only the files it’s given.
86+
:::
87+
88+
While this is *very* convenient for projects with just a few files, passing many files this way can be cumbersome and error-prone.
89+
For larger projects, directories can help.
8290

83-
Passing many files this way can be cumbersome and error-prone. Directories can help.
8491

8592
## Directories
8693

87-
`scala-cli` accepts whole directories as input. This is convenient when you have many
88-
`.scala` files and passing them all one-by-one on the command line isn't practical:
94+
`scala-cli` accepts whole directories as input.
95+
96+
This is convenient when you have many `.scala` files, and passing them all one-by-one on the command line isn't practical:
8997

9098
```scala title=my-app/Messages.scala
9199
object Messages {
@@ -100,30 +108,32 @@ object Hello {
100108
}
101109
```
102110

103-
Run them with
111+
For this case, run all the source code files in `my-app` by supplying the directory name:
112+
104113
```bash
105114
scala-cli my-app
106115
# Hello from Scala
107116
```
108117

109-
From our experience, `scala-cli .` is the most used command (it will compile and run all sources from within current directory.)
118+
In our experience, `scala-cli .` is the most used command; it compiles and runs all sources in the current directory.
110119

111120
:::note
112-
Scala CLI will process all files within the directories and all its subdirectories.
113-
114-
Scala CLI ignores all subdirectories that starts with `.` like `.scala` or `.vscode`. (But such directories can be explicitly provided as inputs.)
121+
Scala CLI process all files within the specified directories and all of its subdirectories.
115122

123+
Scala CLI ignores all subdirectories that start with `.` like `.scala` or `.vscode`.
124+
Such directories needs to be explicitly provided as inputs.
116125
:::
126+
117127
## URLs
118128

119129
:::warning
120-
Running unverified code from the internet may be really dangerous since Scala CLI does not provide any sandboxing at this moment.
130+
Running unverified code from the internet can be very handy for *trusted* sources, but it can also be really dangerous, since Scala CLI does not provide any sandboxing at this moment.
121131

122132
Make sure that you trust the code that you are about to run.
123133
:::
124134

125135
`scala-cli` accepts input via URLs pointing at `.scala` files.
126-
It will download their content, and run them.
136+
It downloads their content, and runs them:
127137

128138
```bash
129139
scala-cli https://gist.github.com/alexarchambault/f972d941bc4a502d70267cfbbc4d6343/raw/2691c01984c9249936a625a42e29a822a357b0f6/Test.scala
@@ -132,8 +142,8 @@ scala-cli https://gist.github.com/alexarchambault/f972d941bc4a502d70267cfbbc4d63
132142

133143
### GitHub Gist
134144

135-
`scala-cli` accepts input via the URLs of GitHub gists.
136-
It wil download the gists' zip archives, cache their content, and run them.
145+
`scala-cli` accepts input via Github Gist’s urls.
146+
It downloads the gist zip archive and runs it:
137147

138148
```bash
139149
scala-cli https://gist.github.com/alexarchambault/7b4ec20c4033690dd750ffd601e540ec
@@ -142,15 +152,17 @@ scala-cli https://gist.github.com/alexarchambault/7b4ec20c4033690dd750ffd601e540
142152

143153
## Piping
144154

145-
You can just pipe Scala code to `scala-cli` for execution:
155+
You can also pipe Scala code to `scala-cli` for execution:
156+
146157
```bash
147158
echo 'println("Hello")' | scala-cli -
148159
# Hello
149160
```
150161

151162
## Process substitution
152163

153-
`scala-cli` accepts input via shell process substitution:
164+
Lastly, `scala-cli` also accepts input via shell process substitution:
165+
154166
```bash
155167
scala-cli <(echo 'println("Hello")')
156168
# Hello

website/docs/commands/clean.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ title: Clean
33
sidebar_position: 16
44
---
55

6-
Deletes all generated files that are a part of your working directory, including the `.scala` directory.
6+
The `clean` command deletes all of the files that are generated by `scala-cli`. This including the `.scala` directory where Scala CLI generated its output and stores its caches.

website/docs/commands/compile.md

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ title: Compile
33
sidebar_position: 5
44
---
55

6-
Scala CLI can compile your code with its `compile` command:
6+
Scala CLI compiles your code with its `compile` command:
7+
78
```bash
89
cat Hello.scala
910
# object Hello {
@@ -13,17 +14,18 @@ cat Hello.scala
1314
scala-cli compile Hello.scala
1415
```
1516

16-
Note that most commands of the Scala CLI will automatically compile your code if necessary.
17-
The `compile` command is useful if you'd like to simply check that your code compiles,
18-
or see compilation warnings, without running it or packaging it for example.
17+
Note that most Scala CLI commands automatically compile your code, if necessary.
18+
The `compile` command is useful if you'd like to check that your code compiles,
19+
or know of compilation warnings, without running it or packaging it.
1920

20-
We list below some options the `compile` command accepts. For a full list of options,
21-
run `scala compile --help`, or check the options linked in the
21+
The most common `compile` options are shown below.
22+
For a full list of options, run `scala compile --help`, or check the options linked in the
2223
[reference documentation](../reference/commands.md#compile).
2324

2425
## Watch mode
2526

26-
`--watch` makes `scala-cli` watch your code for changes, and re-compiles it upon change:
27+
`--watch` makes `scala-cli` watch your code for changes, and re-compiles it upon any change:
28+
2729
```bash
2830
scala-cli compile --watch Hello.scala
2931
# Compiling project-cef76d561e (1 Scala source)
@@ -42,10 +44,11 @@ Scala CLI uses the latest stable version of Scala by default (`3.1.0` when this
4244
scala-cli compile --scala 2.13.6 Hello.scala
4345
```
4446

45-
`scala-cli` should work with all major `2.12.x`, `2.13.x`, and `3.x` Scala versions.
47+
`scala-cli` works with all major `2.12.x`, `2.13.x`, and `3.x` Scala versions.
4648

47-
`--scala` also accepts "short" Scala versions, such as `2.12`, `2`, or `3`. In that
49+
`--scala` also accepts "short" Scala versions, such as `2.12`, `2`, or `3`. In this
4850
case, it picks the highest corresponding stable Scala version:
51+
4952
```bash ignore
5053
scala-cli compile --scala 2.12 Hello.scala
5154
scala-cli compile --scala 2 Hello.scala
@@ -54,26 +57,28 @@ scala-cli compile --scala 3 Hello.scala
5457

5558
## Dependencies
5659

57-
You can add dependencies on the command-line, via `--dependency`:
60+
You can add dependencies on the command-line with `--dependency`:
61+
5862
```bash
5963
scala-cli compile Hello.scala \
6064
--dependency org.scala-lang.modules::scala-parallel-collections:1.0.4
6165
```
6266

63-
Note that `--dependency` is only meant as a convenience. You should favour
64-
adding dependencies in the sources themselves via [using directives](../guides/configuration.md#special-imports).
67+
Note that `--dependency` is only meant as a convenience. You should favor
68+
adding dependencies in the source files themselves via [`using` directives](../guides/configuration.md#special-imports).
69+
70+
You can also add simple JAR files — those that don’t have transitive dependencies — as dependencies, with `--jar`:
6571

66-
You can also add simple JAR files as dependencies, with `--jar`:
6772
```bash
6873
scala-cli compile Hello.scala --jar /path/to/library.jar
6974
```
7075

71-
We have a guide dedicated to [Dependency management](../guides/dependencies.md)
76+
See the [Dependency management](../guides/dependencies.md) guide for more details.
7277

7378
## Scala compiler options
7479

75-
Most [Scala compiler options](https://docs.scala-lang.org/overviews/compiler-options) can be passed as
76-
is to `scala-cli` :
80+
Most [Scala compiler options](https://docs.scala-lang.org/overviews/compiler-options) can be passed as-is to `scala-cli`:
81+
7782
```bash
7883
scala-cli compile Hello.scala -Xlint:infer-any
7984
# Compiling project_b729aa2200-cef76d561e (1 Scala source)
@@ -83,7 +88,8 @@ scala-cli compile Hello.scala -Xlint:infer-any
8388
# Compiled 'project_b729aa2200-cef76d561e'
8489
```
8590

86-
In more detail, all options starting with
91+
All `scala-cli` options that start with:
92+
8793
- `-g`
8894
- `-language`
8995
- `-opt`
@@ -96,15 +102,16 @@ In more detail, all options starting with
96102

97103
are assumed to be Scala compiler options.
98104

99-
Compiler options can also be passed with `-O`:
105+
Scala compiler options can also be passed with `-O`:
106+
100107
```bash
101108
scala-cli compile Hello.scala -O -deprecation -O -Xlint:infer-any
102109
# [warn] ./Hello.scala:3:7: method x in class Some is deprecated (since 2.12.0): Use .value instead.
103110
# [warn] opt.x
104111
# [warn] ^
105112
```
106113

107-
`-O` accepts both options with the prefixes above and those without such a prefix.
114+
`-O` accepts both options with the prefixes shown above, and those without such a prefix.
108115

109116
## Scala compiler plugins
110117
Use `--compiler-plugin` to add compiler plugin dependencies:
@@ -116,18 +123,18 @@ scala-cli compile Main.scala --compiler-plugin org.typelevel:::kind-projector:0.
116123

117124
## Printing a class path
118125

119-
`--class-path` makes `scala compile` print a class path that can be passed to other tools:
126+
`--class-path` makes `scala-cli compile` print a class path:
120127
```bash
121128
scala-cli compile --class-path Hello.scala
122129
# /work/.scala/project-cef76d561e/classes:~/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.12.14/scala-library-2.12.14.jar:~/Library/Caches/ScalaCli/local-repo/0.1.0/org.virtuslab.scala-cli/runner_2.12/0.0.1-SNAPSHOT/jars/runner_2.12.jar:~/Library/Caches/ScalaCli/local-repo/0.1.0/org.virtuslab.scala-cli/stubs/0.0.1-SNAPSHOT/jars/stubs.jar
123130
```
124131

125-
You can pass this class path to `java -cp` for example:
132+
This is handy when working with other tools.
133+
For example, you can pass this class path to `java -cp`:
126134
```bash
127135
java -cp "$(scala compile --class-path Hello.scala)" Hello
128136
# Hello
129137
```
130138

131-
Note that you should favour the [`run`](./run.md) command to run your code, rather than running `java -cp`.
132-
The class path obtained this way is meant for scenarios where `scala-cli` doesn't offer a more
133-
convenient option.
139+
Note that you should favor the [`run`](./run.md) command to run your code, rather than running `java -cp`.
140+
The class path obtained this way is only meant for scenarios where `scala-cli` doesn't offer a more convenient option.

website/docs/commands/fmt.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,30 @@ Scala-cli supports formatting your code using [Scalafmt](https://scalameta.org/s
99
scala-cli fmt
1010
```
1111

12-
Under the hood scala-cli will download and run Scalafmt over your code.
12+
Under the hood, `scala-cli` downloads and runs Scalafmt on your code.
1313

14-
If you are working on setting up a CI, scala-cli also has you covered.
14+
If you’re setting up a continuous integration (CI) server, `scala-cli` also has you covered.
1515
You can check formatting correctness using a `--check` flag:
1616

1717
```bash
1818
scala-cli fmt --check
1919
```
2020

21-
### Dialects
21+
### Dialects
22+
2223
Scala-cli also supports dialects that are passed to the formatter.
23-
This value will only be used if there is no `.scalafmt.conf` file. If that file exists, then all configuration should be placed there.
24-
For a list of all possible values you may want to consult the [official documentation](https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects)
24+
This value is only used if there is no `.scalafmt.conf` file.
25+
However, if it exists, then all configuration should be placed there.
26+
For a list of all possible values, consult the [official Scala Dialects documentation](https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects):
2527

2628
```bash
2729
scala-cli fmt --dialect scala212
2830
```
2931

3032
### Current limitations
31-
Right now scala-cli doesn't read the `.scalafmt.conf` files,
32-
therefore in some scenarios versions of those two may be mismatched.
33-
It is possible to set the version manually if you encounter any issues:
33+
34+
At this time, `scala-cli` doesn't read a `scalafmt` version from `.scalafmt.conf` files.
35+
Therefore, in some scenarios, wrong version may be used. In such situations, it is possible to set the version manually if you encounter any issues:
3436

3537
```bash
3638
scala-cli fmt --scalafmt-tag v3.0.3

0 commit comments

Comments
 (0)