Mercurial > cgi-bin > hgweb.cgi > PassMan
diff src/main/kotlin/name/blackcap/passman/ImportSubcommand.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 | 7a74ae668665 |
children |
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt Sun Jun 30 22:28:52 2024 -0700 +++ b/src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt Tue Jul 02 11:27:39 2024 -0700 @@ -22,23 +22,23 @@ override fun run(args: Array<String>) { parseArguments(args) - db = Database.open() + db = Database.default try { doImport() } catch (e: IOException) { - die(e.message ?: "I/O error") + throw SubcommandException(message = e.message ?: "I/O error", cause = e) } catch (e: CsvException) { - val message = e.message ?: "CSV error" - die("line $line, $message") + val baseMessage = e.message ?: "CSV error" + throw SubcommandException(message = "line $line, $baseMessage", cause = e) } } private fun parseArguments(args: Array<String>) { val params = parseInto("import", args, options) when (params.size) { - 0 -> die("expecting CSV file name", 2) + 0 -> throw SubcommandException(message = "expecting CSV file name", status = 2) 1 -> csvFile = params[0] - else -> die("unexpected trailing arguments", 2) + else -> throw SubcommandException(message = "unexpected trailing arguments", status = 2) } csvDateFormat = SimpleDateFormat(options.format).apply { timeZone = TimeZone.getTimeZone(options.zone) @@ -85,7 +85,7 @@ private fun fromCsv(fields: Array<String>): Entry { if (fields.size != NFIELDS) { - die("line $line, expected $NFIELDS fields but got ${fields.size}") + throw SubcommandException(message = "line $line, expected $NFIELDS fields but got ${fields.size}") } return Entry( name = fields[0], @@ -105,8 +105,7 @@ try { return csvDateFormat.parse(unparsed) } catch (e: ParseException) { - die("${see(unparsed)} - invalid date/time string") - throw e /* kotlin is too stupid to realize this never happens */ + throw SubcommandException(message = "${see(unparsed)} - invalid date/time string", cause = e) } }