File tree Expand file tree Collapse file tree 2 files changed +62
-6
lines changed Expand file tree Collapse file tree 2 files changed +62
-6
lines changed Original file line number Diff line number Diff line change @@ -174,12 +174,23 @@ scala-cli hello.zip
174
174
175
175
## Piping
176
176
177
- You can also pipe Scala code to ` scala-cli ` for execution:
178
-
179
- ``` bash
180
- echo ' println("Hello")' | scala-cli -
181
- # Hello
182
- ```
177
+ You can also pipe code to ` scala-cli ` for execution:
178
+ - scripts
179
+ ``` bash
180
+ echo ' println("Hello")' | scala-cli _.sc
181
+ # Hello
182
+ ```
183
+ - Scala code
184
+ ``` bash
185
+ echo ' @main def hello() = println("Hello")' | scala-cli _.scala
186
+ # Hello
187
+ ```
188
+ - Java code
189
+ ``` bash
190
+ echo ' class Hello { public static void main(String args[]) { System.out.println("Hello"); } }' | scala-cli _.java
191
+ # Hello
192
+ ```
193
+ More details in the [ Piping guide] ( ../guides/piping.md ) .
183
194
184
195
## Scala CLI version
185
196
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Piping
3
+ sidebar_position : 23
4
+ ---
5
+
6
+ # Piping
7
+
8
+ Instead of passing paths to your sources, you can also pipe your code via standard input:
9
+ ``` bash
10
+ echo ' @main def hello() = println("Hello")' | scala-cli _
11
+ # Hello
12
+ ```
13
+
14
+ ## Wildcards
15
+ The ` _ ` wildcard implies that the piped code is a standard Scala app.
16
+ It is also possible to pass a script or Java code, when using the appropriate wildcard.
17
+ The available options are as follows:
18
+ - for standard Scala code use ` _ ` , ` _.scala ` or ` -.scala ` ;
19
+ - for Scala scripts use ` - ` , ` _.sc ` or ` -.sc ` ;
20
+ - for Java code use ` _.java ` or ` -.java ` .
21
+
22
+ ## Examples
23
+ - scripts
24
+ ``` bash
25
+ echo ' println("Hello")' | scala-cli _.sc
26
+ # Hello
27
+ ```
28
+ - Scala code
29
+ ``` bash
30
+ echo ' @main def hello() = println("Hello")' | scala-cli _.scala
31
+ # Hello
32
+ ```
33
+ - Java code
34
+ ``` bash
35
+ echo ' class Hello { public static void main(String args[]) { System.out.println("Hello"); } }' | scala-cli _.java
36
+ # Hello
37
+ ```
38
+
39
+ ## Mixing piped sources with on-disk ones
40
+ It is also possible to pipe some code via standard input, while the rest of your code is on-disk.
41
+ ``` bash
42
+ echo ' case class HelloMessage(msg: String)' > HelloMessage.scala
43
+ echo ' @main def hello() = println(HelloMessage(msg = "Hello").msg)' | scala-cli _ HelloMessage.scala
44
+ # Hello
45
+ ```
You can’t perform that action at this time.
0 commit comments