Factor initialization of datadir (#15)

Fixes #14.
This commit is contained in:
Pierre-Marie Padiou 2024-03-27 10:16:15 +01:00 committed by GitHub
parent 3fc693e722
commit ce86e82854
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -106,8 +106,6 @@ class Phoenixd : CliktCommand() {
// the additionalValues map already contains values in phoenix.conf, so if we are here then there are no existing password // the additionalValues map already contains values in phoenix.conf, so if we are here then there are no existing password
terminal.print(yellow("Generating default api password...")) terminal.print(yellow("Generating default api password..."))
val value = randomBytes32().toHex() val value = randomBytes32().toHex()
val confFile = datadir / "phoenix.conf"
FileSystem.SYSTEM.createDirectories(datadir)
FileSystem.SYSTEM.appendingSink(confFile, mustExist = false).buffer().use { it.writeUtf8("\nhttp-password=$value\n") } FileSystem.SYSTEM.appendingSink(confFile, mustExist = false).buffer().use { it.writeUtf8("\nhttp-password=$value\n") }
terminal.println(white("done")) terminal.println(white("done"))
value value
@ -154,6 +152,7 @@ class Phoenixd : CliktCommand() {
).default(Verbosity.Default, defaultForHelp = "prints high-level info to the console") ).default(Verbosity.Default, defaultForHelp = "prints high-level info to the console")
init { init {
FileSystem.SYSTEM.createDirectories(datadir)
context { context {
valueSource = MapValueSource(readConfFile(confFile)) valueSource = MapValueSource(readConfFile(confFile))
helpFormatter = { MordantHelpFormatter(it, showDefaultValues = true) } helpFormatter = { MordantHelpFormatter(it, showDefaultValues = true) }
@ -170,7 +169,6 @@ class Phoenixd : CliktCommand() {
@OptIn(DelicateCoroutinesApi::class) @OptIn(DelicateCoroutinesApi::class)
override fun run() { override fun run() {
FileSystem.SYSTEM.createDirectories(datadir)
if (seed.isNew && !agreeToTermsOfService) { if (seed.isNew && !agreeToTermsOfService) {
runBlocking { runBlocking {
terminal.println(green("Backup")) terminal.println(green("Backup"))