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 | 30 |
1 files changed, 15 insertions, 15 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 6eab66b..cb95619 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Command.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Command.kt | |||
@@ -7,25 +7,25 @@ import java.util.* | |||
7 | */ | 7 | */ |
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 | fun toCommandLineOption(): 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> = LinkedList() | 14 | private val opts: MutableList<Option> = LinkedList() |
15 | private val args: MutableList<String> = LinkedList() | 15 | private val args: MutableList<String> = LinkedList() |
16 | 16 | ||
17 | fun withOption(key: String, value: String? = null): Command { | 17 | fun withOption(key: String, value: String? = null): Command { |
18 | this.opts.add(Option(key, value)) | 18 | this.opts.add(Option(key, value)) |
19 | return this | 19 | return this |
20 | } | 20 | } |
21 | 21 | ||
22 | fun withArguments(vararg args: String): Command { | 22 | fun withArguments(vararg args: String): Command { |
23 | this.args.addAll(Arrays.asList(*args)) | 23 | this.args.addAll(Arrays.asList(*args)) |
24 | return this | 24 | return this |
25 | } | 25 | } |
26 | 26 | ||
27 | fun asList(): List<String> = listOf(cmd) + opts.map { it.toCommandLineOption() } + args | 27 | fun asList(): List<String> = listOf(cmd) + opts.map { it.toCommandLineOption() } + args |
28 | 28 | ||
29 | fun asArray(): Array<String> = this.asList().toTypedArray() | 29 | fun asArray(): Array<String> = this.asList().toTypedArray() |
30 | 30 | ||
31 | } | 31 | } |