Mercurial > cgi-bin > hgweb.cgi > PassMan
view 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 source
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) } val db = Database.open() 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) } }