aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/org/pacien/tincapp/commands/Command.kt
diff options
context:
space:
mode:
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.kt36
1 files changed, 36 insertions, 0 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
new file mode 100644
index 0000000..9b22d5f
--- /dev/null
+++ b/app/src/main/java/org/pacien/tincapp/commands/Command.kt
@@ -0,0 +1,36 @@
1package org.pacien.tincapp.commands
2
3import java.util.*
4
5/**
6 * @author pacien
7 */
8internal class Command(private val cmd: String) {
9
10 private data class Option(val key: String, val value: String?) {
11 override fun toString(): String = if (value != null) "--$key=$value" else "--$key"
12 }
13
14 private val opts: MutableList<Option>
15 private val args: MutableList<String>
16
17 init {
18 this.opts = LinkedList<Option>()
19 this.args = LinkedList<String>()
20 }
21
22 fun withOption(key: String, value: String? = null): Command {
23 this.opts.add(Option(key, value))
24 return this
25 }
26
27 fun withArguments(vararg args: String): Command {
28 this.args.addAll(Arrays.asList(*args))
29 return this
30 }
31
32 fun asList(): List<String> = listOf(cmd) + opts.map { it.toString() } + args
33
34 fun asArray(): Array<String> = this.asList().toTypedArray()
35
36}