Skip to content

Commit fb43f8c

Browse files
authored
Refactor the docs to reduce ignored (non-coverable by tests) code snippet examples (#1617)
1 parent 1becd2d commit fb43f8c

File tree

13 files changed

+576
-238
lines changed

13 files changed

+576
-238
lines changed

website/docs/commands/basics.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,18 @@ Make sure that you trust the code that you are about to run.
173173
`scala-cli` accepts input via URLs pointing at `.scala` files.
174174
It downloads their content, and runs them:
175175

176+
<ChainedSnippet>
177+
176178
```bash
177179
scala-cli https://gist.github.com/alexarchambault/f972d941bc4a502d70267cfbbc4d6343/raw/2691c01984c9249936a625a42e29a822a357b0f6/Test.scala
178-
# Hello from Scala GitHub Gist
179180
```
180181

182+
```text
183+
Hello from Scala GitHub Gist
184+
```
185+
186+
</ChainedSnippet>
187+
181188
### GitHub Gist
182189

183190
`scala-cli` accepts input via Github Gist’s urls.

website/docs/commands/compile.md

Lines changed: 162 additions & 102 deletions
Large diffs are not rendered by default.

website/docs/commands/package.md

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Package
33
sidebar_position: 17
44
---
55

6+
import {ChainedSnippets} from "../../src/components/MarkdownComponents.js";
7+
68
The `package` command can package your Scala code in various formats, such as:
79
- [lightweight launcher JARs](#default-package-format)
810
- [standard library JARs](#library-jars)
@@ -30,12 +32,19 @@ object Hello {
3032
}
3133
```
3234

35+
<ChainedSnippets>
36+
3337
```bash
3438
scala-cli package Hello.scala -o hello
3539
./hello
36-
# Hello
3740
```
3841

42+
```text
43+
Hello
44+
```
45+
46+
</ChainedSnippets>
47+
3948
<!-- Expected
4049
Hello
4150
-->
@@ -54,16 +63,23 @@ class MyLibrary {
5463
```
5564

5665

66+
<ChainedSnippets>
67+
5768
```bash
5869
scala-cli package MyLibrary.scala -o my-library.jar --library
5970
javap -cp my-library.jar mylib.MyLibrary
60-
# Compiled from "MyLibrary.scala"
61-
# public class mylib.MyLibrary {
62-
# public java.lang.String message();
63-
# public mylib.MyLibrary();
64-
# }
6571
```
6672

73+
```text
74+
Compiled from "MyLibrary.scala"
75+
public class mylib.MyLibrary {
76+
public java.lang.String message();
77+
public mylib.MyLibrary();
78+
}
79+
```
80+
81+
</ChainedSnippets>
82+
6783
<!-- Expected:
6884
MyLibrary.scala
6985
public class mylib.MyLibrary
@@ -87,12 +103,19 @@ object Hello {
87103
}
88104
```
89105

106+
<ChainedSnippets>
107+
90108
```bash
91109
scala-cli package Hello.scala -o hello --assembly
92110
./hello
93-
# Hello
94111
```
95112

113+
```text
114+
Hello
115+
```
116+
117+
</ChainedSnippets>
118+
96119
<!-- Expected:
97120
Hello
98121
-->
@@ -123,11 +146,18 @@ Started building docker image with your application
123146
docker run hello-docker:latest
124147
-->
125148

149+
<ChainedSnippets>
150+
126151
```bash
127152
docker run hello-docker
128-
# Hello from Docker
129153
```
130154

155+
```text
156+
Hello from Docker
157+
```
158+
159+
</ChainedSnippets>
160+
131161
<!-- Expected:
132162
Hello from Docker
133163
-->
@@ -174,12 +204,19 @@ object Hello {
174204
}
175205
```
176206

207+
<ChainedSnippets>
208+
177209
```bash
178210
scala-cli package --js HelloJs.scala -o hello.js
179211
node hello.js
180-
# Hello
181212
```
182213

214+
```text
215+
Hello
216+
```
217+
218+
</ChainedSnippets>
219+
183220
<!-- Expected:
184221
Hello
185222
-->
@@ -202,12 +239,19 @@ object Hello {
202239
}
203240
```
204241

242+
<ChainedSnippets>
243+
205244
```bash
206245
scala-cli package Hello.scala -o hello --native-image
207246
./hello
208-
# Hello
209247
```
210248

249+
```text
250+
Hello
251+
```
252+
253+
</ChainedSnippets>
254+
211255
<!-- Expected:
212256
Hello
213257
-->
@@ -235,14 +279,27 @@ object Hello {
235279
}
236280
```
237281

282+
<ChainedSnippets>
283+
238284
```bash
239285
scala-cli package --native HelloNative.scala -S 2.13.6 -o hello
240286
file hello
241-
# hello: Mach-O 64-bit executable x86_64
287+
```
288+
289+
```text
290+
hello: Mach-O 64-bit executable x86_64
291+
```
292+
293+
```bash
242294
./hello
243-
# Hello
244295
```
245296

297+
```text
298+
Hello
299+
```
300+
301+
</ChainedSnippets>
302+
246303
<!-- Expected:
247304
Hello
248305
-->
@@ -264,14 +321,27 @@ object Hello {
264321
}
265322
```
266323

324+
<ChainedSnippets>
325+
267326
```bash ignore
268327
scala-cli package --deb Hello.scala -o hello.deb
269328
file hello
270-
# hello: Mach-O 64-bit executable x86_64
329+
```
330+
331+
```text
332+
hello: Mach-O 64-bit executable x86_64
333+
```
334+
335+
```bash ignore
271336
./hello
272-
# Hello
273337
```
274338

339+
```text
340+
Hello
341+
```
342+
343+
</ChainedSnippets>
344+
275345
### Debian
276346

277347
DEB is the package format for the Debian Linux distribution.
@@ -371,7 +441,7 @@ Instead of passing the `package` options directly from bash, it is possible to p
371441
372442
This using directive makes it possible to define the type of the package generated by the `package` command. For example:
373443
374-
```
444+
```scala compile
375445
//> using packaging.packageType "assembly"
376446
```
377447
@@ -381,7 +451,7 @@ Available types: `assembly`, `raw-assembly`, `bootstrap`, `library`, `source`, `
381451
382452
This using directive makes it possible to define the destination path of the package generated by the `package` command. For example:
383453
384-
```
454+
```scala compile
385455
//> using packaging.output "foo"
386456
```
387457

website/docs/commands/repl.md

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,46 @@ title: REPL
33
sidebar_position: 8
44
---
55

6+
import {ChainedSnippets} from "../../src/components/MarkdownComponents.js";
7+
68
The `repl` command starts a Scala REPL, which lets you interactively run your code and inspect its results:
79

10+
<ChainedSnippets>
11+
812
```bash ignore
913
scala-cli repl
10-
# scala> println("Hello Scala")
11-
# Hello Scala
12-
#
13-
# scala> :exit
1414
```
1515

16+
```text
17+
scala> println("Hello Scala")
18+
Hello Scala
19+
20+
scala> :exit
21+
```
22+
23+
</ChainedSnippets>
24+
1625
Scala CLI by default uses the normal Scala REPL.
1726

1827
If you prefer to use the [Ammonite REPL](https://ammonite.io/#Ammonite-REPL), specify `--amm` to launch it rather than the default REPL:
1928

29+
<ChainedSnippets>
30+
2031
```bash ignore
2132
scala-cli repl --amm
22-
# Loading...
23-
# Welcome to the Ammonite Repl 2.4.0-23-76673f7f (Scala 3.0.2 Java 11.0.11)
24-
# @ println("Hello ammonite")
25-
# Hello ammonite
26-
# @ exit
27-
# Bye!
2833
```
2934

35+
```text
36+
Loading...
37+
Welcome to the Ammonite Repl 2.4.0-23-76673f7f (Scala 3.0.2 Java 11.0.11)
38+
@ println("Hello ammonite")
39+
Hello ammonite
40+
@ exit
41+
Bye!
42+
```
43+
44+
</ChainedSnippets>
45+
3046
The `repl` command accepts the same arguments as the [compile](./compile.md) command. It first compiles any provided sources, and then exposes those results and any provided dependencies to the REPL session:
3147

3248
```scala title=mylibrary/Messages.scala
@@ -37,14 +53,22 @@ object Messages {
3753
def print(): Unit = println(message)
3854
}
3955
```
56+
57+
<ChainedSnippets>
58+
4059
```bash ignore
4160
scala-cli repl mylibrary/Messages.scala
42-
# Compiling project (Scala 3.0.2, JVM)
43-
# Compiled project (Scala 3.0.2, JVM)
44-
# scala> import mylibrary._
45-
#
46-
# scala> Messages.print()
47-
# Hello
48-
#
49-
# scala> :quit
5061
```
62+
63+
```text
64+
Compiling project (Scala 3.0.2, JVM)
65+
Compiled project (Scala 3.0.2, JVM)
66+
scala> import mylibrary._
67+
68+
scala> Messages.print()
69+
Hello
70+
71+
scala> :quit
72+
```
73+
74+
</ChainedSnippets>

0 commit comments

Comments
 (0)