Changed addCommand -> addArg. Added 'addArg' to JVM/SSH exec

This commit is contained in:
nathan 2020-08-10 14:13:28 +02:00
parent 1fa9e60f9f
commit db1118a733
3 changed files with 77 additions and 6 deletions

View File

@ -119,9 +119,9 @@ open class Executor {
* http://bugs.java.com/view_bug.do?bug_id=7028124 * http://bugs.java.com/view_bug.do?bug_id=7028124
* https://bugs.openjdk.java.net/browse/JDK-6518827 * https://bugs.openjdk.java.net/browse/JDK-6518827
*/ */
internal fun fixArguments(command: List<String>): List<String> { internal fun fixArguments(command: Iterable<String>): List<String> {
if (!IS_OS_WINDOWS) { if (!IS_OS_WINDOWS) {
return command return command.toList()
} }
val result = mutableListOf<String>().apply{ addAll(command) } val result = mutableListOf<String>().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 * 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. * @return This process executor.
*/ */
fun addCommand(vararg command: String): Executor { fun addArg(vararg arguments: String): Executor {
val fixed = fixArguments(listOf(*command)) 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<String>): Executor {
val fixed = fixArguments(arguments)
builder.command().addAll(fixed) builder.command().addAll(fixed)
return this return this
} }

View File

@ -251,6 +251,34 @@ class JvmExecOptions(private val executor: Executor) {
return this 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<String>): JvmExecOptions {
executor.addArg(arguments)
return this
}
/** /**
* Executes the JAVA sub process. * Executes the JAVA sub process.
* *

View File

@ -172,6 +172,34 @@ class SshExecOptions(val executor: Executor) {
return this 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<String>): SshExecOptions {
executor.addArg(arguments)
return this
}
/** /**
* Executes the JAVA sub process. * Executes the JAVA sub process.