8000 Add more docs for piping sources by Gedochao · Pull Request #1053 · VirtusLab/scala-cli · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add more docs for piping sources #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions website/docs/commands/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,23 @@ scala-cli hello.zip

## Piping

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

```bash
echo 'println("Hello")' | scala-cli -
# Hello
```
You can also pipe code to `scala-cli` for execution:
- scripts
```bash
echo 'println("Hello")' | scala-cli _.sc
# Hello
```
- Scala code
```bash
echo '@main def hello() = println("Hello")' | scala-cli _.scala
# Hello
```
- Java code
```bash
echo 'class Hello { public static void main(String args[]) { System.out.println("Hello"); } }' | scala-cli _.java
# Hello
```
More details in the [Piping guide](../guides/piping.md).

## Scala CLI version

Expand Down
45 changes: 45 additions & 0 deletions website/docs/guides/piping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Piping
sidebar_position: 23
---

# Piping

Instead of passing paths to your sources, you can also pipe your code via standard input:
```bash
echo '@main def hello() = println("Hello")' | scala-cli _
# Hello
```

## Wildcards
The `_` wildcard implies that the piped code is a standard Scala app.
It is also possible to pass a script or Java code, when using the appropriate wildcard.
The available options are as follows:
- for standard Scala code use `_`, `_.scala` or `-.scala`;
- for Scala scripts use `-`, `_.sc` or `-.sc`;
- for Java code use `_.java` or `-.java`.

## Examples
- scripts
```bash
echo 'println("Hello")' | scala-cli _.sc
# Hello
```
- Scala code
```bash
echo '@main def hello() = println("Hello")' | scala-cli _.scala
# Hello
```
- Java code
```bash
echo 'class Hello { public static void main(String args[]) { System.out.println("Hello"); } }' | scala-cli _.java
# Hello
```

## Mixing piped sources with on-disk ones
It is also possible to pipe some code via standard input, while the rest of your code is on-disk.
```bash
echo 'case class HelloMessage(msg: String)' > HelloMessage.scala
echo '@main def hello() = println(HelloMessage(msg = "Hello").msg)' | scala-cli _ HelloMessage.scala
# Hello
```
0