diff src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt @ 3:eafa3779aef8

More bug fixes, quote strings in diagnostics.
author David Barts <n5jrn@me.com>
date Sun, 11 Sep 2022 20:36:06 -0700
parents a6cfdffcaa94
children 711cc42e96d7
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt	Sun Sep 11 18:24:55 2022 -0700
+++ b/src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt	Sun Sep 11 20:36:06 2022 -0700
@@ -2,6 +2,19 @@
 
 class DeleteSubcommand(): Subcommand() {
     override fun run(args: Array<String>) {
-        println("Not yet implemented")
+        if (args.isEmpty()) {
+            die("expecting a site name", 2)
+        }
+        if (args.size > 1) {
+            die("unexpected trailing arguments", 2)
+        }
+        val nameIn = args[0]
+        val db = Database.open()
+        db.connection.prepareStatement("delete from passwords where id = ?").use {
+            it.setLong(1, db.makeKey(nameIn))
+            if (it.executeUpdate() == 0) {
+                die("no record matches ${see(nameIn)}")
+            }
+        }
     }
 }
\ No newline at end of file