Mercurial > cgi-bin > hgweb.cgi > PassMan
view src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt @ 12:a38a2a1036c3
Add import subcommand.
author | David Barts <n5jrn@me.com> |
---|---|
date | Sun, 22 Jan 2023 09:22:53 -0800 |
parents | 72619175004e |
children | ea65ab890f66 |
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) } if (args[0] == "-h" || args[0].startsWith("--h")) { println("usage: passman delete name [...]") exitProcess(0) } 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) } }