From db1118a73354c0a21af0f3947a141fe1ff96beee Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 10 Aug 2020 14:13:28 +0200 Subject: [PATCH] Changed addCommand -> addArg. Added 'addArg' to JVM/SSH exec --- src/dorkbox/executor/Executor.kt | 27 +++++++++++++++++++------ src/dorkbox/executor/JvmExecOptions.kt | 28 ++++++++++++++++++++++++++ src/dorkbox/executor/SshExecOptions.kt | 28 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 6 deletions(-) diff --git a/src/dorkbox/executor/Executor.kt b/src/dorkbox/executor/Executor.kt index 5df8357..38430fc 100644 --- a/src/dorkbox/executor/Executor.kt +++ b/src/dorkbox/executor/Executor.kt @@ -119,9 +119,9 @@ open class Executor { * http://bugs.java.com/view_bug.do?bug_id=7028124 * https://bugs.openjdk.java.net/browse/JDK-6518827 */ - internal fun fixArguments(command: List): List { + internal fun fixArguments(command: Iterable): List { if (!IS_OS_WINDOWS) { - return command + return command.toList() } val result = mutableListOf().apply{ addAll(command) } @@ -357,16 +357,31 @@ open class Executor { } /** - * Add a program (or it's arguments) which are being executed. + * Add arguments to an existing command, which will be executed. * * This does not replace commands, it adds to them * - * @param command A string array containing the program and/or its arguments. + * @param arguments A string array containing the program and/or its arguments. * * @return This process executor. */ - fun addCommand(vararg command: String): Executor { - val fixed = fixArguments(listOf(*command)) + fun addArg(vararg arguments: String): Executor { + val fixed = fixArguments(listOf(*arguments)) + builder.command().addAll(fixed) + return this + } + + /** + * Add arguments to an existing command, which will be executed. + * + * This does not replace commands, it adds to them + * + * @param arguments A string array containing the program and/or its arguments. + * + * @return This process executor. + */ + fun addArg(arguments: Iterable): Executor { + val fixed = fixArguments(arguments) builder.command().addAll(fixed) return this } diff --git a/src/dorkbox/executor/JvmExecOptions.kt b/src/dorkbox/executor/JvmExecOptions.kt index 6907899..d60678e 100644 --- a/src/dorkbox/executor/JvmExecOptions.kt +++ b/src/dorkbox/executor/JvmExecOptions.kt @@ -251,6 +251,34 @@ class JvmExecOptions(private val executor: Executor) { return this } + /** + * Add arguments to an existing command, which will be executed. + * + * This does not replace commands, it adds to them + * + * @param arguments A string array containing the program and/or its arguments. + * + * @return This process executor. + */ + fun addArg(vararg arguments: String): JvmExecOptions { + executor.addArg(*arguments) + return this + } + + /** + * Add arguments to an existing command, which will be executed. + * + * This does not replace commands, it adds to them + * + * @param arguments A string array containing the program and/or its arguments. + * + * @return This process executor. + */ + fun addArg(arguments: Iterable): JvmExecOptions { + executor.addArg(arguments) + return this + } + /** * Executes the JAVA sub process. * diff --git a/src/dorkbox/executor/SshExecOptions.kt b/src/dorkbox/executor/SshExecOptions.kt index 7dd36e3..d94a06a 100644 --- a/src/dorkbox/executor/SshExecOptions.kt +++ b/src/dorkbox/executor/SshExecOptions.kt @@ -172,6 +172,34 @@ class SshExecOptions(val executor: Executor) { return this } + /** + * Add arguments to an existing command, which will be executed. + * + * This does not replace commands, it adds to them + * + * @param arguments A string array containing the program and/or its arguments. + * + * @return This process executor. + */ + fun addArg(vararg arguments: String): SshExecOptions { + executor.addArg(*arguments) + return this + } + + /** + * Add arguments to an existing command, which will be executed. + * + * This does not replace commands, it adds to them + * + * @param arguments A string array containing the program and/or its arguments. + * + * @return This process executor. + */ + fun addArg(arguments: Iterable): SshExecOptions { + executor.addArg(arguments) + return this + } + /** * Executes the JAVA sub process.