Mercurial > cgi-bin > hgweb.cgi > PassMan
annotate src/main/kotlin/name/blackcap/passman/DeleteSubcommand.kt @ 25:131e39d96862
Fix erroneous help message in read subcommand.
author | David Barts <n5jrn@me.com> |
---|---|
date | Thu, 04 Jul 2024 09:49:36 -0700 |
parents | 07406c4af4a5 |
children |
rev | line source |
---|---|
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
1 package name.blackcap.passman |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
2 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
3 class DeleteSubcommand(): Subcommand() { |
22 | 4 override fun run(args: Array<String>) { |
3
eafa3779aef8
More bug fixes, quote strings in diagnostics.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
5 if (args.isEmpty()) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
6 throw SubcommandException(message = "expecting a site name", status = 2) |
3
eafa3779aef8
More bug fixes, quote strings in diagnostics.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
7 } |
9 | 8 if (args[0] == "-h" || args[0].startsWith("--h")) { |
9 println("usage: passman delete name [...]") | |
22 | 10 return |
9 | 11 } |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
12 val db = Database.default |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
13 var errors = 0 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
14 for (nameIn in args) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
15 db.connection.prepareStatement("delete from passwords where id = ?").use { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
16 it.setLong(1, db.makeKey(nameIn)) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
17 if (it.executeUpdate() == 0) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
18 error("no record matches ${see(nameIn)}") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
19 errors++ |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
20 } |
3
eafa3779aef8
More bug fixes, quote strings in diagnostics.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
21 } |
eafa3779aef8
More bug fixes, quote strings in diagnostics.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
22 } |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
23 if (errors > 0) { |
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
24 throw SubcommandException() |
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
25 } |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
26 } |
8 | 27 } |