Mercurial > cgi-bin > hgweb.cgi > PassMan
diff src/main/kotlin/name/blackcap/passman/PasswordSubcommand.kt @ 21:ea65ab890f66
More work to support interactive feature.
author | David Barts <n5jrn@me.com> |
---|---|
date | Tue, 02 Jul 2024 11:27:39 -0700 |
parents | 0fc90892a3ae |
children |
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/PasswordSubcommand.kt Sun Jun 30 22:28:52 2024 -0700 +++ b/src/main/kotlin/name/blackcap/passman/PasswordSubcommand.kt Tue Jul 02 11:27:39 2024 -0700 @@ -3,23 +3,22 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardCopyOption -import kotlin.system.exitProcess class PasswordSubcommand : Subcommand() { override fun run(args: Array<String>) { // Parse arguments if (args.size > 0 && (args[0] == "-h" || args[0].startsWith("--h"))) { println("usage: passman password") - exitProcess(0) + return } if (!args.isEmpty()) { - die("unexpected arguments", 2) + throw SubcommandException(message = "unexpected arguments", status = 2) } // Open databases println("Changing database encryption key...") val oldPath = Path.of(DB_FILE) - val oldDb = Database.open(fileName = DB_FILE, passwordPrompt = "Old database key: ") + val oldDb = Database.default val newPath = Path.of(NEW_DB_FILE) if (Files.exists(newPath)) { println("WARNING: deleting ${see(NEW_DB_FILE)}") @@ -31,7 +30,9 @@ println("WARNING: do not interrupt this process or data may be lost!") copyRecords(oldDb, newDb) - // Wrap up + // Wrap up. XXX - this closes Database.default, so this subcommand may + // only be invoked directly from the shell prompt, never in interactive + // mode. oldDb.connection.close() newDb.connection.close() Files.move(newPath, oldPath, StandardCopyOption.REPLACE_EXISTING)