view src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt @ 4:02b101422726

See bugs.
author David Barts <n5jrn@me.com>
date Sun, 11 Sep 2022 20:44:59 -0700
parents eafa3779aef8
children 711cc42e96d7
line wrap: on
line source

package name.blackcap.passman

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)}")
            }
        }
    }
}