Mercurial > cgi-bin > hgweb.cgi > PassMan
diff src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt @ 6:711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
author | David Barts <n5jrn@me.com> |
---|---|
date | Tue, 20 Sep 2022 20:52:21 -0700 |
parents | eafa3779aef8 |
children | 698c4a3d758d |
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt Sun Sep 11 21:29:20 2022 -0700 +++ b/src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt Tue Sep 20 20:52:21 2022 -0700 @@ -1,20 +1,23 @@ package name.blackcap.passman +import kotlin.system.exitProcess + class DeleteSubcommand(): Subcommand() { override fun run(args: Array<String>) { 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)}") + var errors = 0 + for (nameIn in args) { + db.connection.prepareStatement("delete from passwords where id = ?").use { + it.setLong(1, db.makeKey(nameIn)) + if (it.executeUpdate() == 0) { + error("no record matches ${see(nameIn)}") + errors++ + } } } + exitProcess(if (errors > 0) 1 else 0) } } \ No newline at end of file