Skip to content

Commit

Permalink
Quit flag not suppresses compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Jan 20, 2023
1 parent ac1091e commit b58b51b
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 28 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
21 changes: 16 additions & 5 deletions modules/cli/src/main/scala/scala/cli/internal/CliLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ class CliLogger(
}
}

def error(message: String) =
out.println(message)
def error(message: String) = {
System.err.println(verbosity)
if (verbosity >= -1)
out.println(message)
}

def message(message: => String) =
if (verbosity >= 0)
out.println(message)
Expand Down Expand Up @@ -123,14 +127,20 @@ class CliLogger(
printDiagnostic(ex.positions, Severity.Error, ex.getMessage(), contentCache, None)
}

def log(ex: BuildException): Unit =
def log(ex: BuildException): Unit = {
System.err.println("Hello")
if (verbosity >= 0)
printEx(ex, new mutable.HashMap)
}

def debug(ex: BuildException): Unit =
def debug(ex: BuildException): Unit = {
System.err.println("Hello-debug")
if (verbosity >= 2)
printEx(ex, new mutable.HashMap)
def exit(ex: BuildException): Nothing =
}

def exit(ex: BuildException): Nothing = {
System.err.println("Hello-error")
if (verbosity < 0)
sys.exit(1)
else if (verbosity == 0) {
Expand All @@ -139,6 +149,7 @@ class CliLogger(
}
else
throw new Exception(ex)
}

def coursierLogger(printBefore: String) =
if (quiet)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 fail
scala-cli Hello.scala -q
```

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

<!-- Expected:
[error] ./Hello.scala:6:3: ')' expected, but '}' found
[error] }
[error] ^
-->

</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 b58b51b

Please sign in to comment.