Skip to content

Commit 6e25f7d

Browse files
committed
NIT refactor docs
- apply the `ChainedSnippets` component where applicable - update deprecated behaviours
1 parent fcc9a12 commit 6e25f7d

File tree

2 files changed

+136
-21
lines changed

2 files changed

+136
-21
lines changed

website/docs/commands/basics.md

Lines changed: 125 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Basics
33
sidebar_position: 3
44
---
55

6+
import {ChainedSnippets} from "../../src/components/MarkdownComponents.js";
7+
68
Scala CLI is a command line tool that executes a given sub-command on the inputs it’s provided with, using a
79
given [configuration](../guides/configuration.md) to produce a result.
810

@@ -60,11 +62,18 @@ object Hello {
6062

6163
Then run it by passing it to `scala-cli`:
6264

65+
<ChainedSnippets>
66+
6367
```bash
6468
scala-cli Hello.scala
65-
# Hello from Scala
6669
```
6770

71+
```text
72+
Hello from Scala
73+
```
74+
75+
</ChainedSnippets>
76+
6877
You can also split your code into multiple files:
6978

7079
```scala title=Messages.scala
@@ -82,11 +91,18 @@ object Hello {
8291

8392
and the run them with `scala-cli`:
8493

94+
<ChainedSnippets>
95+
8596
```bash
8697
scala-cli Hello.scala Messages.scala
87-
# Hello from Scala
8898
```
8999

100+
```text
101+
Hello from Scala
102+
```
103+
104+
</ChainedSnippets>
105+
90106
:::note
91107
Scala CLI compiles only the provided inputs.
92108
For example, if we provide only one of the files above:
@@ -124,11 +140,18 @@ object Hello {
124140

125141
In this case, you can run all the source code files in `my-app` by supplying the directory name:
126142

143+
<ChainedSnippets>
144+
127145
```bash
128146
scala-cli my-app
129-
# Hello from Scala
130147
```
131148

149+
```text
150+
Hello from Scala
151+
```
152+
153+
</ChainedSnippets>
154+
132155
In our experience, `scala-cli .` is the most used command; it compiles and runs all sources in the current directory.
133156

134157
:::note
@@ -160,11 +183,20 @@ scala-cli https://gist.github.com/alexarchambault/f972d941bc4a502d70267cfbbc4d63
160183
`scala-cli` accepts input via Github Gist’s urls.
161184
It downloads the gist zip archive and runs it:
162185

186+
<ChainedSnippets>
187+
163188
```bash
164189
scala-cli https://gist.github.com/alexarchambault/7b4ec20c4033690dd750ffd601e540ec
165-
# Hello
166190
```
167191

192+
```text
193+
Hello
194+
```
195+
196+
</ChainedSnippets>
197+
198+
More details in the [GitHub gists cookbook](../cookbooks/gists.md).
199+
168200
### Zip archive
169201

170202
`scala-cli` accepts inputs via a `zip` archive path.
@@ -176,45 +208,93 @@ object Hello extends App {
176208
}
177209
```
178210

211+
<ChainedSnippets>
212+
179213
```bash ignore
180214
unzip -l hello.zip
181-
# Archive: hello.zip
182-
# Length Date Time Name
183-
# --------- ---------- ----- ----
184-
# 49 12-07-2021 00:06 Hello.scala
185-
# --------- -------
186-
# 49 1 file
215+
```
216+
217+
```text
218+
Archive: hello.zip
219+
Length Date Time Name
220+
--------- ---------- ----- ----
221+
49 12-07-2021 00:06 Hello.scala
222+
--------- -------
223+
49 1 file
224+
```
225+
226+
```bash ignore
187227
scala-cli hello.zip
188-
# Hello
189228
```
190229

230+
```text
231+
Hello
232+
```
233+
234+
</ChainedSnippets>
235+
191236
## Piping
192237

193238
You can also pipe code to `scala-cli` for execution:
194239

195240
- scripts
241+
242+
<ChainedSnippets>
243+
196244
```bash
197245
echo 'println("Hello")' | scala-cli _.sc
198-
# Hello
199246
```
247+
248+
```text
249+
Hello
250+
```
251+
252+
</ChainedSnippets>
253+
200254
- Scala code
255+
256+
<ChainedSnippets>
257+
201258
```bash
202259
echo '@main def hello() = println("Hello")' | scala-cli _.scala
203-
# Hello
204260
```
261+
262+
```text
263+
Hello
264+
```
265+
266+
</ChainedSnippets>
267+
205268
- Java code
269+
270+
<ChainedSnippets>
271+
206272
```bash
207273
echo 'class Hello { public static void main(String args[]) { System.out.println("Hello"); } }' | scala-cli _.java
208-
# Hello
209274
```
275+
276+
```text
277+
Hello
278+
```
279+
280+
</ChainedSnippets>
281+
210282
- Markdown code (experimental)
283+
284+
<ChainedSnippets>
285+
211286
```bash
212287
echo '# Example Snippet
213288
```scala
214289
println("Hello")
215290
```' | scala-cli _.md
216-
# Hello
217291
```
292+
293+
```text
294+
Hello
295+
```
296+
297+
</ChainedSnippets>
218298

219299
More details in the [Piping guide](../guides/piping.md).
220300

@@ -227,31 +307,56 @@ Running another Scala CLI version might be slower because it uses JVM-based Scal
227307

228308
To run another Scala CLI version, specify it with `--cli-version` before any other argument:
229309

310+
<ChainedSnippets>
311+
230312
```bash
231-
scala-cli --cli-version 0.1.3-51-g4d314eee-SNAPSHOT about
232-
# Scala CLI version 0.1.3-51-g4d314eee-SNAPSHOT
313+
scala-cli --cli-version 0.1.17-62-g21e1cf44-SNAPSHOT about
314+
```
315+
316+
```text
317+
Scala CLI version: 0.1.17-62-g21e1cf44-SNAPSHOT
318+
Scala version (default): 3.2.1
233319
```
234320

321+
</ChainedSnippets>
322+
235323
<!-- Expected:
236-
Scala CLI version 0.1.3-51-g4d314eee-SNAPSHOT
324+
Scala CLI version: 0.1.17-62-g21e1cf44-SNAPSHOT
325+
Scala version (default): 3.2.1
237326
-->
238327

239328
To use the latest Scala CLI nightly build, pass `nightly` to `--cli-version` parameter:
240329

330+
<ChainedSnippets>
331+
241332
```bash
242333
scala-cli --cli-version nightly about
243-
# Scala CLI version 0.1.3-8-g431cc15f-SNAPSHOT
244334
```
245335

336+
```text
337+
Fetching Scala CLI 0.1.17-62-g21e1cf44-SNAPSHOT
338+
Scala CLI version: 0.1.17-62-g21e1cf44-SNAPSHOT
339+
Scala version (default): 3.2.1
340+
```
341+
342+
</ChainedSnippets>
343+
246344
## Process substitution
247345

248346
Lastly, `scala-cli` also accepts input via shell process substitution:
249347

348+
<ChainedSnippets>
349+
250350
```bash
251351
scala-cli <(echo 'println("Hello")')
252-
# Hello
253352
```
254353

354+
```text
355+
Hello
356+
```
357+
358+
</ChainedSnippets>
359+
255360
<!-- Expected:
256361
Hello
257362
-->

website/docs/cookbooks/gists.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ object Hello extends App {
6464
println(inputs.mkString(","))
6565
}
6666
```
67+
6768
```scala title=input
6869
1
6970
2
@@ -72,10 +73,19 @@ object Hello extends App {
7273
```
7374

7475
and run them:
76+
77+
<ChainedSnippets>
78+
7579
```bash
7680
scala-cli https://gist.github.com/lwronski/7ee12fa4b8b8bac3211841273df82080
77-
# 1,2,3,4
7881
```
82+
83+
```text
84+
1,2,3,4
85+
```
86+
87+
</ChainedSnippets>
88+
7989
<!-- Expected:
8090
1,2,3,4
8191
-->

0 commit comments

Comments
 (0)