implemented 10-cli-commands.md: added CLI commands for branch name resolution, one-shot builds, failed build retries, and build status reports; includes tests for functionality and edge cases
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package de.hoennig.gittally.commands
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.PrintStream
|
||||
|
||||
data class CapturedConsole(
|
||||
val stdout: String,
|
||||
val stderr: String,
|
||||
)
|
||||
|
||||
/** Captures `System.out` and `System.err` while [block] runs. */
|
||||
fun captureConsole(block: () -> Unit): CapturedConsole {
|
||||
val out = ByteArrayOutputStream()
|
||||
val err = ByteArrayOutputStream()
|
||||
val previousOut = System.out
|
||||
val previousErr = System.err
|
||||
System.setOut(PrintStream(out, true))
|
||||
System.setErr(PrintStream(err, true))
|
||||
try {
|
||||
block()
|
||||
} finally {
|
||||
System.setOut(previousOut)
|
||||
System.setErr(previousErr)
|
||||
}
|
||||
return CapturedConsole(out.toString(), err.toString())
|
||||
}
|
||||
Reference in New Issue
Block a user