diff options
Diffstat (limited to 'app/src/main/java/org/pacien/tincapp/commands')
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Command.kt | 13 | ||||
-rw-r--r-- | app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | 11 |
2 files changed, 4 insertions, 20 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 | ||
diff --git a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt index e8ebb21..9b57233 100644 --- a/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt +++ b/app/src/main/java/org/pacien/tincapp/commands/Tinc.kt | |||
@@ -13,17 +13,6 @@ object Tinc { | |||
13 | .withOption("config", AppPaths.confDir(netName).absolutePath) | 13 | .withOption("config", AppPaths.confDir(netName).absolutePath) |
14 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) | 14 | .withOption("pidfile", AppPaths.pidFile(netName).absolutePath) |
15 | 15 | ||
16 | // independently runnable commands | ||
17 | |||
18 | @Throws(IOException::class) | ||
19 | fun fsck(netName: String, fix: Boolean): List<String> { | ||
20 | var cmd = newCommand(netName).withArguments("fsck") | ||
21 | if (fix) cmd = cmd.withOption("force") | ||
22 | return Executor.call(cmd) | ||
23 | } | ||
24 | |||
25 | // commands requiring a running tinc daemon | ||
26 | |||
27 | @Throws(IOException::class) | 16 | @Throws(IOException::class) |
28 | fun stop(netName: String) { | 17 | fun stop(netName: String) { |
29 | Executor.call(newCommand(netName).withArguments("stop")) | 18 | Executor.call(newCommand(netName).withArguments("stop")) |