Skip to content
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

Add option to print yaml logs to Stdout #82

Merged
merged 3 commits into from
May 12, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ case class LintCommand(
@PositionalArguments queryExpressions: List[String] = Nil,
app: Application = Application.default
) extends Command {
def run(): Int = app.completeEither(runResult())
val silence: Boolean = lintReportPath.exists { p => p.toString() == "-" }
def run(): Int = app.completeEither(runResult(), silence)

def runResult(): Result[Either[Diagnostic, Unit]] = {
val expr = queryExpressions.mkString(" ")
Expand Down Expand Up @@ -112,7 +113,6 @@ case class LintCommand(

private def writeLintReport(conflicts: List[LintDiagnostic], path: Option[Path]): Unit =
path
.map(p => if (p.isAbsolute()) p else app.env.workingDirectory.resolve(p))
.foreach { out =>
val grouped = conflicts.groupBy(_.target).toList.sortBy(_._1)
val docs = grouped.map {
Expand All @@ -129,9 +129,28 @@ case class LintCommand(
)
}
val rendered = Doc.intercalate(Doc.line, docs).render(Int.MaxValue)
Files.createDirectories(out.getParent())
Files.write(out, rendered.getBytes(StandardCharsets.UTF_8))
if (out.toString() == "-") {
writeToStdout(rendered)
} else {
writeToFile(rendered, out)
}
}

def writeToStdout(report: String): Unit = {
app.println("# -------- Begin Lint Result")
app.println(report)
app.println("# -------- End Lint Result")
}

def writeToFile(report: String, path: Path): Unit = {
val pathAbs = if (path.isAbsolute()) {
path
} else {
app.env.workingDirectory.resolve(path)
}
Files.createDirectories(pathAbs.getParent())
Files.write(pathAbs, report.getBytes(StandardCharsets.UTF_8))
}
}

object LintCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ object MultidepsEnrichments {
def isTesting: Boolean =
app.env.isSettingTrue("MULTIDEPS_TESTING")

def completeEither(result: Result[Either[Diagnostic, Unit]]): Int =
def completeEither(result: Result[Either[Diagnostic, Unit]], silence: Boolean = false): Int =
result match {
case ValueResult(Right(())) =>
app.reporter.exitCode()
case ValueResult(Left(diagnostic)) =>
app.reporter.log(diagnostic)
if (!silence) {
app.reporter.log(diagnostic)
}
100
case ErrorResult(error) =>
app.reporter.log(error)
if (!silence) {
app.reporter.log(error)
}
1
}

Expand Down