Skip to content

Commit

Permalink
Quit flag not suppresses compilation errors (#1792)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Jan 23, 2023
1 parent c13c105 commit 2664838
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ object ConsoleBloopBuildClient {
"." + File.separator + p.relativeTo(Os.pwd).toString
case Right(p) => p.toString
}
logger.message(s"$prefix$path0:$line$col" + (if (msgIt.hasNext) " " + msgIt.next() else ""))
logger.error(s"$prefix$path0:$line$col" + (if (msgIt.hasNext) " " + msgIt.next() else ""))
for (line <- msgIt)
logger.message(prefix + line)
val codeOpt = {
Expand All @@ -199,15 +199,15 @@ object ConsoleBloopBuildClient {
} yield line
}
for (code <- codeOpt)
code.linesIterator.map(prefix + _).foreach(logger.message(_))
code.linesIterator.map(prefix + _).foreach(logger.error(_))
val canPrintUnderline = diag.getRange.getStart.getLine == diag.getRange.getEnd.getLine &&
diag.getRange.getStart.getCharacter != null &&
diag.getRange.getEnd.getCharacter != null &&
codeOpt.nonEmpty
if (canPrintUnderline) {
val len =
math.max(1, diag.getRange.getEnd.getCharacter - diag.getRange.getStart.getCharacter)
logger.message(
logger.error(
prefix + " " * diag.getRange.getStart.getCharacter + "^" * len
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final case class LoggingOptions(
@Recurse
verbosityOptions: VerbosityOptions = VerbosityOptions(),
@Group("Logging")
@HelpMessage("Decrease verbosity")
@HelpMessage("Decrease logging verbosity")
@Tag(tags.implementation)
@Name("q")
quiet: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect

class LoggingTests extends ScalaCliSuite {
test("single -q should not suppresses compilation errors") {
TestInputs(
os.rel / "Hello.scala" ->
s"""object Hello extends App {
| println("Hello"
|}
|""".stripMargin
).fromRoot { root =>
val res =
os.proc(TestUtil.cli, ".", "-q").call(cwd = root, check = false, mergeErrIntoOut = true)
val output = res.out.trim()
expect(output.contains("Hello.scala:3:1"))
expect(output.contains("error"))
}
}
test("single -q should not suppresses output from app") {
TestInputs(
os.rel / "Hello.scala" ->
s"""object Hello extends App {
| println("Hello")
|}
|""".stripMargin
).fromRoot { root =>
val res = os.proc(TestUtil.cli, ".", "-q").call(cwd = root)
val output = res.out.trim()
expect(output.contains("Hello"))
}
}
}
33 changes: 33 additions & 0 deletions website/docs/commands/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,36 @@ Hello
<!-- Expected:
Hello
-->

### Logging

To turn off logging in the application, pass the `-q` flag once. This will suppress all logging output except for errors:

```scala title=Hello.scala
object Hello extends App {
println("Hello"
}
```

<ChainedSnippets>

```bash run-fail
scala-cli Hello.scala -q
```

```text
[error] ./Hello.scala:6:3: ')' expected, but '}' found
[error] }
[error] ^
Compilation failed
```

<!-- Expected:
')' expected, but '}' found
Compilation failed
-->

</ChainedSnippets>

Note that this will also suppress any logging related to tasks such as downloading dependencies, logs
about the start of compilation, and so on.
2 changes: 1 addition & 1 deletion website/docs/reference/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ Available in commands:

Aliases: `-q`

Decrease verbosity
Decrease logging verbosity

### `--progress`

Expand Down
2 changes: 1 addition & 1 deletion website/docs/reference/scala-command/cli-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ Aliases: `-q`

`IMPLEMENTATION specific` per Scala Runner specification

Decrease verbosity
Decrease logging verbosity

### `--progress`

Expand Down
34 changes: 17 additions & 17 deletions website/docs/reference/scala-command/runner-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Enable actionable diagnostics

**--quiet**

Decrease verbosity
Decrease logging verbosity

Aliases: `-q`

Expand Down Expand Up @@ -827,7 +827,7 @@ Enable actionable diagnostics

**--quiet**

Decrease verbosity
Decrease logging verbosity

Aliases: `-q`

Expand Down Expand Up @@ -1354,7 +1354,7 @@ Enable actionable diagnostics

**--quiet**

Decrease verbosity
Decrease logging verbosity

Aliases: `-q`

Expand Down Expand Up @@ -1911,7 +1911,7 @@ Enable actionable diagnostics

**--quiet**

Decrease verbosity
Decrease logging verbosity

Aliases: `-q`

Expand Down Expand Up @@ -2490,7 +2490,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -3019,7 +3019,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -3614,7 +3614,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -3929,7 +3929,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -4206,7 +4206,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -4519,7 +4519,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -4598,7 +4598,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -4657,7 +4657,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -4748,7 +4748,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -5025,7 +5025,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -5350,7 +5350,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -5529,7 +5529,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down Expand Up @@ -5586,7 +5586,7 @@ Enable actionable diagnostics
**--quiet**
Decrease verbosity
Decrease logging verbosity
Aliases: `-q`
Expand Down

0 comments on commit 2664838

Please sign in to comment.