Mercurial > cgi-bin > hgweb.cgi > PassMan
comparison 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 |
comparison
equal
deleted
inserted
replaced
5:ad997df1f560 | 6:711cc42e96d7 |
---|---|
1 package name.blackcap.passman | 1 package name.blackcap.passman |
2 | |
3 import kotlin.system.exitProcess | |
2 | 4 |
3 class DeleteSubcommand(): Subcommand() { | 5 class DeleteSubcommand(): Subcommand() { |
4 override fun run(args: Array<String>) { | 6 override fun run(args: Array<String>) { |
5 if (args.isEmpty()) { | 7 if (args.isEmpty()) { |
6 die("expecting a site name", 2) | 8 die("expecting a site name", 2) |
7 } | 9 } |
8 if (args.size > 1) { | |
9 die("unexpected trailing arguments", 2) | |
10 } | |
11 val nameIn = args[0] | |
12 val db = Database.open() | 10 val db = Database.open() |
13 db.connection.prepareStatement("delete from passwords where id = ?").use { | 11 var errors = 0 |
14 it.setLong(1, db.makeKey(nameIn)) | 12 for (nameIn in args) { |
15 if (it.executeUpdate() == 0) { | 13 db.connection.prepareStatement("delete from passwords where id = ?").use { |
16 die("no record matches ${see(nameIn)}") | 14 it.setLong(1, db.makeKey(nameIn)) |
15 if (it.executeUpdate() == 0) { | |
16 error("no record matches ${see(nameIn)}") | |
17 errors++ | |
18 } | |
17 } | 19 } |
18 } | 20 } |
21 exitProcess(if (errors > 0) 1 else 0) | |
19 } | 22 } |
20 } | 23 } |