You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/commands/basics.md
+51-39Lines changed: 51 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,36 +3,40 @@ title: Basics
3
3
sidebar_position: 3
4
4
---
5
5
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.
7
7
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:
14
9
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.
16
18
17
19
## Input formats
18
20
19
21
The `scala-cli` CLI commands accept input in a number of ways, most notably:
22
+
20
23
- as source files
21
-
- as one or several directories, containing sources
24
+
- as one or several directories that contain source files
22
25
- as URLs, pointing to sources
23
-
- by piping or process substitution source code directly
26
+
- by processing source code via piping or process substitution
24
27
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.
26
29
27
30
## Source files
28
31
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:
33
33
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:
36
40
37
41
```scala title=Hello.scala
38
42
objectHello {
@@ -41,13 +45,14 @@ object Hello {
41
45
}
42
46
```
43
47
44
-
Run it with
48
+
The run it by passing it to `scala-cli`:
49
+
45
50
```bash
46
51
scala-cli Hello.scala
47
52
# Hello from Scala
48
53
```
49
54
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:
51
56
52
57
```scala title=Messages.scala
53
58
objectMessages {
@@ -62,30 +67,33 @@ object Hello {
62
67
}
63
68
```
64
69
65
-
Run them with
70
+
and the run them with `scala-cli`:
71
+
66
72
```bash
67
73
scala-cli Hello.scala Messages.scala
68
74
# Hello from Scala
69
75
```
70
76
71
77
:::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:
76
80
77
81
```bash fail
78
82
scala-cli Hello.scala
79
83
```
80
84
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.
82
90
83
-
Passing many files this way can be cumbersome and error-prone. Directories can help.
84
91
85
92
## Directories
86
93
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:
89
97
90
98
```scala title=my-app/Messages.scala
91
99
objectMessages {
@@ -100,30 +108,32 @@ object Hello {
100
108
}
101
109
```
102
110
103
-
Run them with
111
+
For this case, run all the source code files in `my-app` by supplying the directory name:
112
+
104
113
```bash
105
114
scala-cli my-app
106
115
# Hello from Scala
107
116
```
108
117
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.
110
119
111
120
:::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.
115
122
123
+
Scala CLI ignores all subdirectories that start with `.` like `.scala` or `.vscode`.
124
+
Such directories needs to be explicitly provided as inputs.
116
125
:::
126
+
117
127
## URLs
118
128
119
129
:::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.
121
131
122
132
Make sure that you trust the code that you are about to run.
123
133
:::
124
134
125
135
`scala-cli` accepts input via URLs pointing at `.scala` files.
Copy file name to clipboardExpand all lines: website/docs/commands/clean.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,4 +3,4 @@ title: Clean
3
3
sidebar_position: 16
4
4
---
5
5
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.
Copy file name to clipboardExpand all lines: website/docs/commands/fmt.md
+10-8Lines changed: 10 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,28 +9,30 @@ Scala-cli supports formatting your code using [Scalafmt](https://scalameta.org/s
9
9
scala-cli fmt
10
10
```
11
11
12
-
Under the hoodscala-cli will download and run Scalafmt over your code.
12
+
Under the hood, `scala-cli` downloads and runs Scalafmt on your code.
13
13
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.
15
15
You can check formatting correctness using a `--check` flag:
16
16
17
17
```bash
18
18
scala-cli fmt --check
19
19
```
20
20
21
-
### Dialects
21
+
### Dialects
22
+
22
23
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):
25
27
26
28
```bash
27
29
scala-cli fmt --dialect scala212
28
30
```
29
31
30
32
### 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:
0 commit comments