Skip to content

Commit 2425c3a

Browse files
committed
add config subcommand for faster setup
1 parent d06f902 commit 2425c3a

File tree

8 files changed

+48
-23
lines changed

8 files changed

+48
-23
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# cli-obs-remote
22

3+
### setup
4+
5+
enable and configure OBS websocket
6+
7+
run `obsremote config` to create a default config and open it in the default editor
8+

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin.Companion.shadowJar
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.shadowJar
22
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
33

44
plugins {

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pluginManagement {
1414
plugins {
1515
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
1616
// See https://jmfayard.github.io/refreshVersions
17-
id("de.fayard.refreshVersions") version "0.60.5"
17+
id("de.fayard.refreshVersions") version "0.60.6"
1818
}
1919
rootProject.name = "obsremote"
2020

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package moe.nikky.vrcobs.cli
22

3+
import FILESYSTEM
34
import com.github.ajalt.clikt.core.Context
45
import com.github.ajalt.mordant.animation.animation
56
import com.github.ajalt.mordant.rendering.AnsiLevel
67
import com.github.ajalt.mordant.terminal.Terminal
78
import dotenv.getEnv
89
import exec
10+
import io.github.oshai.kotlinlogging.KotlinLogging
911
import kotlinx.coroutines.channels.Channel
1012
import kotlinx.coroutines.coroutineScope
1113
import kotlinx.coroutines.delay
@@ -19,26 +21,42 @@ import okio.Path.Companion.toPath
1921
import kotlin.math.sin
2022
import kotlin.time.Duration.Companion.milliseconds
2123

22-
object ConfigCommand: BaseCommand(
24+
object ConfigCommand : BaseCommand(
2325
"config"
2426
) {
27+
private val logger = KotlinLogging.logger {}
2528
override fun help(context: Context): String {
2629
return """
2730
opens the .env file
2831
""".trimIndent()
2932
}
33+
3034
@OptIn(ExperimentalCoroutinesApi::class)
3135
override suspend fun run(): Unit = coroutineScope {
3236
val homedir = getEnv("HOME")?.toPath() ?: getEnv("USERPROFILE")?.toPath()
33-
?: error("cannot find home directory from envionment")
37+
?: error("cannot find home directory from envionment")
3438
val dotenvFile = homedir / ".config/obsremote/.env".toPath(normalize = true)
35-
println("opening $dotenvFile")
39+
if (!FILESYSTEM.exists(dotenvFile)) {
40+
FILESYSTEM.createDirectories(homedir / ".config/obsremote/".toPath(normalize = true))
41+
logger.info { "creating $dotenvFile" }
42+
FILESYSTEM.write(dotenvFile) {
43+
writeUtf8(
44+
"""
45+
# dotenv
46+
OBS_HOST=127.0.0.1
47+
OBS_PORT=4455
48+
OBS_PASSWORD=
49+
""".trimIndent()
50+
)
51+
}
52+
}
53+
logger.info { "opening $dotenvFile" }
3654
//TODO: check if we are on unix and use xdg-open
3755
try {
3856
exec("explorer.exe", dotenvFile.toString())
39-
}catch (e: IllegalStateException){
57+
} catch (e: IllegalStateException) {
4058
e.printStackTrace()
4159
println("failed to open file")
4260
}
43-
}
44-
}
61+
}
62+
}

src/commonMain/kotlin/moe/nikky/vrcobs/cli/RootCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class RootCommand : BaseCommand(
2525
BitrateGroup,
2626
GraphCommand,
2727
ViewersCommand,
28-
// ConfigCommand
28+
ConfigCommand
2929
)
3030
}
3131

src/commonMain/kotlin/moe/nikky/vrcobs/obsSession.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ suspend fun obsSession(
6363
val session = ObsSessionBuilder(client).apply {
6464
host = connectionProps.host
6565
port = connectionProps.port
66-
password = connectionProps.password
66+
if(!connectionProps.password.isNullOrBlank()) {
67+
password = connectionProps.password
68+
}
6769

6870
eventSubs = ObsEventSubs.General + ObsEventSubs.MediaInputs
6971
// eventSubs = ObsEventSubs.General + ObsEventSubs.Inputs

src/nativeMain/kotlin/exec.native.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ actual fun exec(
2323

2424
val status = pclose?.invoke(fp)
2525
if (status != 0) {
26-
error("Command `$command` failed with status $status${if (redirectStderr) ": $stdout" else ""}")
26+
error("Command `[${command.joinToString()}]` failed with status $status${if (redirectStderr) ": $stdout" else ""}")
2727
}
2828

2929
return if (trim) stdout.trim() else stdout
30-
}
30+
}

versions.properties

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#### Dependencies and Plugin versions with their available updates.
2-
#### Generated by `./gradlew refreshVersions` version 0.60.5
2+
#### Generated by `./gradlew refreshVersions` version 0.60.6
33
####
44
#### Don't manually edit or split the comments that start with four hashtags (####),
55
#### they will be overwritten by refreshVersions.
66
####
77
#### suppress inspection "SpellCheckingInspection" for whole file
88
#### suppress inspection "UnusedProperty" for whole file
99

10-
plugin.dev.reformator.stacktracedecoroutinator=2.5.4
10+
plugin.dev.reformator.stacktracedecoroutinator=2.5.7
1111

12-
plugin.com.gradleup.shadow=9.0.0-rc1
12+
plugin.com.gradleup.shadow=9.2.2
1313

14-
version.ch.qos.logback..logback-classic=1.5.18
14+
version.ch.qos.logback..logback-classic=1.5.19
1515

1616
version.com.github.ajalt.clikt..clikt=5.0.3
1717

@@ -28,21 +28,20 @@ version.com.saveourtool.okio-extras..okio-extras=1.1.3
2828
## unused
2929
version.io.github.cdimascio..dotenv-kotlin=6.5.1
3030

31-
version.io.github.oshai..kotlin-logging=7.0.7
31+
version.io.github.oshai..kotlin-logging=7.0.13
3232

33-
version.io.github.rejeq..ktobs-core=0.4.0
33+
version.io.github.rejeq..ktobs-core=0.4.1
3434

35-
version.io.github.rejeq..ktobs-ktor=0.4.0
35+
version.io.github.rejeq..ktobs-ktor=0.4.1
3636

37-
version.kotlin=2.2.0
38-
## # available=2.2.20-Beta1
37+
version.kotlin=2.2.20
3938

4039
version.kotlinx.coroutines=1.10.2
4140

4241
version.kotlinx.datetime=0.7.1-0.6.x-compat
4342

4443
version.kotlinx.serialization=1.9.0
4544

46-
version.ktor=3.2.2
45+
version.ktor=3.3.0
4746

48-
version.okio=3.15.0
47+
version.okio=3.16.0

0 commit comments

Comments
 (0)