11package moe.nikky.vrcobs.cli
22
3+ import FILESYSTEM
34import com.github.ajalt.clikt.core.Context
45import com.github.ajalt.mordant.animation.animation
56import com.github.ajalt.mordant.rendering.AnsiLevel
67import com.github.ajalt.mordant.terminal.Terminal
78import dotenv.getEnv
89import exec
10+ import io.github.oshai.kotlinlogging.KotlinLogging
911import kotlinx.coroutines.channels.Channel
1012import kotlinx.coroutines.coroutineScope
1113import kotlinx.coroutines.delay
@@ -19,26 +21,42 @@ import okio.Path.Companion.toPath
1921import kotlin.math.sin
2022import 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+ }
0 commit comments