diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands/Command.kt')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Command.kt | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Command.kt b/app/src/main/java/org/pacien/tincapp/commands/Command.kt index 9b22d5f..6eab66b 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Command.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Command.kt | |||
@@ -8,16 +8,11 @@ import java.util.* | |||
8 | internal class Command(private val cmd: String) { | 8 | internal class Command(private val cmd: String) { |
9 | 9 | ||
10 | private data class Option(val key: String, val value: String?) { | 10 | private data class Option(val key: String, val value: String?) { |
11 | override fun toString(): String = if (value != null) "--$key=$value" else "--$key" | 11 | fun toCommandLineOption(): String = if (value != null) "--$key=$value" else "--$key" |
12 | } | 12 | } |
13 | 13 | ||
14 | private val opts: MutableList<Option> | 14 | private val opts: MutableList<Option> = LinkedList() |
15 | private val args: MutableList<String> | 15 | private val args: MutableList<String> = LinkedList() |
16 | |||
17 | init { | ||
18 | this.opts = LinkedList<Option>() | ||
19 | this.args = LinkedList<String>() | ||
20 | } | ||
21 | 16 | ||
22 | fun withOption(key: String, value: String? = null): Command { | 17 | fun withOption(key: String, value: String? = null): Command { |
23 | this.opts.add(Option(key, value)) | 18 | this.opts.add(Option(key, value)) |
@@ -29,7 +24,7 @@ internal class Command(private val cmd: String) { | |||
29 | return this | 24 | return this |
30 | } | 25 | } |
31 | 26 | ||
32 | fun asList(): List<String> = listOf(cmd) + opts.map { it.toString() } + args | 27 | fun asList(): List<String> = listOf(cmd) + opts.map { it.toCommandLineOption() } + args |
33 | 28 | ||
34 | fun asArray(): Array<String> = this.asList().toTypedArray() | 29 | fun asArray(): Array<String> = this.asList().toTypedArray() |
35 | 30 | ||