Skip to content

Commit

Permalink
chore: update todos
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 8, 2023
1 parent 0cca6a4 commit 63a471d
Showing 1 changed file with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,25 @@ class Command {
return doExecute(processBuilder, options)
}

fun exec(commandLine: String, args: List<String> = listOf(), options: ExecOptions): Int {
fun exec(commandLine: String, args: List<String> = emptyList(), options: ExecOptions): Int {
if (!options.silent) {
logger.info("Executing: $commandLine ${args.joinToString(" ")}")
}

val newArgs = args + commandLine
val processBuilder = ProcessBuilder("bash", "-c", *newArgs.toTypedArray())
val commandWithArgs = mutableListOf("bash", "-c", "$commandLine ${args.joinToString(" ")}")
val processBuilder = ProcessBuilder(*commandWithArgs.toTypedArray())

return doExecute(processBuilder, options)
}

private fun doExecute(processBuilder: ProcessBuilder, options: ExecOptions): Int {
val process = processBuilder
.directory(File(options.cwd))
.start()

val process = processBuilder.directory(File(options.cwd)).start()
val exitCode = process.waitFor()

process.inputStream.bufferedReader().use { it ->
it.forEachLine { line ->
options.listeners.stdout(line)
}
}
process.inputStream.bufferedReader().forEachLine(options.listeners::stdout)

if (exitCode != 0 && !options.ignoreReturnCode) {
process.errorStream.bufferedReader().use {
it.forEachLine { line ->
options.listeners.stderr(line)
}
}
process.errorStream.bufferedReader().forEachLine(options.listeners::stderr)
}

return exitCode
Expand All @@ -50,7 +40,7 @@ class Command {
companion object {
private val logger: Logger = LoggerFactory.getLogger(Command::class.java)

fun exec(commandLine: String, args: List<String> = listOf(), options: ExecOptions = ExecOptions()): Int {
fun exec(commandLine: String, args: List<String> = emptyList(), options: ExecOptions = ExecOptions()): Int {
return Command().exec(commandLine, args, options)
}
}
Expand Down

0 comments on commit 63a471d

Please sign in to comment.