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
terminal.print(yellow("Generating default api password..."))
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") }
terminal.println(white("done"))
value
@ -154,6 +152,7 @@ class Phoenixd : CliktCommand() {
).default(Verbosity.Default, defaultForHelp = "prints high-level info to the console")
init {
FileSystem.SYSTEM.createDirectories(datadir)
context {
valueSource = MapValueSource(readConfFile(confFile))
helpFormatter = { MordantHelpFormatter(it, showDefaultValues = true) }
@ -170,7 +169,6 @@ class Phoenixd : CliktCommand() {
@OptIn(DelicateCoroutinesApi::class)
override fun run() {
FileSystem.SYSTEM.createDirectories(datadir)
if (seed.isNew && !agreeToTermsOfService) {
runBlocking {
terminal.println(green("Backup"))