Skip to content

Commit

Permalink
NIT changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Jul 12, 2022
1 parent 3978873 commit 6d700c4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import scala.build.blooprifle.BloopRifleConfig
import scala.build.{Build, BuildThreads, Directories, Inputs}
import scala.build.compiler.{BloopCompilerMaker, SimpleScalaCompilerMaker}
import scala.build.errors.BuildException
import scala.build.internal.Util
import scala.build.options.BuildOptions
import scala.util.control.NonFatal
import scala.util.Try
Expand Down Expand Up @@ -44,7 +45,9 @@ final case class TestInputs(
forcedWorkspace = forcedWorkspaceOpt.map(_.resolveFrom(tmpDir))
)
res match {
case Left(err) => sys.error(err)
case Left(err) =>
Util.printException(err)
sys.error(err.getMessage)
case Right(inputs) => f(tmpDir, inputs)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package scala.build.errors

class WrongSourcePathError(exceptionMessage: String, cause: Throwable)
extends BuildException(
message = s"""The file path argument in the using directives at could not be found!
|$exceptionMessage""".stripMargin,
message =
s"""The file path argument in the using directives at could not be found!
|""".stripMargin + exceptionMessage,
cause = cause
)
9 changes: 5 additions & 4 deletions website/docs/commands/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ swiftly.)

## Define source files in using directives

You can also add sources files with using directive `//> using file`:
You can also add source files with the using directive `//> using file`:

```scala title=Main.scala
//> using file "Utils.scala"
Expand All @@ -81,22 +81,23 @@ object Utils {
}
```

`scala-cli` compiles and adds to the class path source `Utils.scala`
`scala-cli` takes into account and compiles `Utils.scala`.

```bash
scala-cli Main.scala
# Hello World
```

<!-- Expected:
Hello World
-->

It is also possible to pass multiple paths to source files in one using directive:
It is also possible to pass multiple paths to source files in a single using directive:
```
//> using files "Utils.scala" "Helper.scala"
```

Note that `//> using file` using directive supports only `Java`, `Scala`, `ScalaScripts` files or directory.
Note that the `//> using file` using directive only supports `.java`, `.scala`, `.sc` files or a directory.

## Watch mode

Expand Down
26 changes: 26 additions & 0 deletions website/docs/guides/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,32 @@ world
</ChainedSnippets>
### Define source files in using directives
You can also add source files with the using directive `//> using file` in Scala scripts:
```scala title=main.sc
//> using file "Utils.scala"
println(Utils.message)
```
```scala title=Utils.scala
object Utils {
val message = "Hello World"
}
```
`scala-cli` takes into account and compiles `Utils.scala`.
```bash
scala-cli main.sc
# Hello World
```
<!-- Expected:
Hello World
-->
### Difference with Ammonite scripts
[Ammonite](http://ammonite.io) is a popular REPL for Scala that can also compile and run `.sc` files.
Expand Down

0 comments on commit 6d700c4

Please sign in to comment.