diff src/main/kotlin/name/blackcap/passman/DeleteSubcommand.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 72619175004e
children 07406c4af4a5
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt	Sun Jun 30 22:28:52 2024 -0700
+++ b/src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt	Tue Jul 02 11:27:39 2024 -0700
@@ -1,17 +1,15 @@
 package name.blackcap.passman
 
-import kotlin.system.exitProcess
-
 class DeleteSubcommand(): Subcommand() {
-    override fun run(args: Array<String>) {
+    override fun run(args: Array<String>): {
         if (args.isEmpty()) {
-            die("expecting a site name", 2)
+            throw SubcommandException(message = "expecting a site name", status = 2)
         }
         if (args[0] == "-h" || args[0].startsWith("--h")) {
             println("usage: passman delete name [...]")
-            exitProcess(0)
+            return 0
         }
-        val db = Database.open()
+        val db = Database.default
         var errors = 0
         for (nameIn in args) {
             db.connection.prepareStatement("delete from passwords where id = ?").use {
@@ -22,6 +20,8 @@
                 }
             }
         }
-        exitProcess(if (errors > 0) 1 else 0)
+        if (errors > 0) {
+            throw SubcommandException()
+        }
     }
 }