Mercurial > cgi-bin > hgweb.cgi > PassMan
diff src/main/kotlin/name/blackcap/passman/ListSubcommand.kt @ 21:ea65ab890f66
More work to support interactive feature.
author | David Barts <n5jrn@me.com> |
---|---|
date | Tue, 02 Jul 2024 11:27:39 -0700 |
parents | 72619175004e |
children | 07406c4af4a5 |
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/ListSubcommand.kt Sun Jun 30 22:28:52 2024 -0700 +++ b/src/main/kotlin/name/blackcap/passman/ListSubcommand.kt Tue Jul 02 11:27:39 2024 -0700 @@ -2,7 +2,6 @@ import org.apache.commons.cli.* import java.util.regex.PatternSyntaxException -import kotlin.system.exitProcess class ListSubcommand(): Subcommand() { private companion object { @@ -57,14 +56,14 @@ try { commandLine = DefaultParser().parse(options, args) } catch (e: ParseException) { - die(e.message ?: "syntax error", 2) + throw SubcommandException(message = e.message ?: "syntax error", cause = e, status = 2) } if (commandLine.hasOption(HELP)) { HelpFormatter().printHelp("$SHORTNAME list [options]", options) - exitProcess(0) + return } if (commandLine.args.isNotEmpty()) { - die("unexpected trailing arguments", 2) + throw SubcommandException(message = "unexpected trailing arguments", status = 2) } STRING_OPTIONS.forEach { @@ -82,7 +81,7 @@ } matchers[it.name]!! += { x -> x is String && x.contains(Regex(value, regexOptions)) } } catch (e: PatternSyntaxException) { - die("${see(value)} - invalid regular expression") + throw SubcommandException(message = "${see(value)} - invalid regular expression", cause = e, status = 2) } } } @@ -90,7 +89,7 @@ TIME_OPTIONS.forEach { commandLine.getOptionValues(it.name)?.forEach { rawValue -> if (rawValue.isEmpty()) { - die("empty string is not a valid time expression") + throw SubcommandException(message = "empty string is not a valid time expression") } val (op, exp) = when(rawValue.first()) { '+', '>' -> Pair<Char, String>('>', rawValue.substring(1)) @@ -100,8 +99,7 @@ } val value = parseDateTime(exp) if (value == null) { - die("${see(rawValue)} - invalid time expression") - throw RuntimeException("will never happen") + throw SubcommandException(message = "${see(rawValue)} - invalid time expression") } if (it.name !in matchers) { matchers[it.name] = mutableListOf<(Any?) -> Boolean>() @@ -117,7 +115,7 @@ } private fun runQuery(): Unit { - val db = Database.open() + val db = Database.default db.connection.prepareStatement("select $NAME, $USERNAME, $NOTES, $CREATED, $MODIFIED, $ACCESSED from passwords").use { val results = it.executeQuery()