comparison src/main/kotlin/name/blackcap/passman/ExportSubcommand.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 07406c4af4a5
comparison
equal deleted inserted replaced
20:4391afcf6bd0 21:ea65ab890f66
16 private lateinit var csvDateFormat: SimpleDateFormat 16 private lateinit var csvDateFormat: SimpleDateFormat
17 private lateinit var db: Database 17 private lateinit var db: Database
18 private val options = ImportExportArguments() 18 private val options = ImportExportArguments()
19 private lateinit var csvFile: String 19 private lateinit var csvFile: String
20 20
21 override fun run(args: Array<String>) { 21 override fun run(args: Array<String>): {
22 parseArguments(args) 22 parseArguments(args)
23 db = Database.open() 23 db = Database.default
24 try { 24 try {
25 doExport() 25 doExport()
26 } catch (e: IOException) { 26 } catch (e: IOException) {
27 die(e.message ?: "I/O error") 27 throw SubcommandException(message = e.message ?: "I/O error", cause = e)
28 } 28 }
29 } 29 }
30 30
31 private fun parseArguments(args: Array<String>) { 31 private fun parseArguments(args: Array<String>) {
32 val params = parseInto("export", args, options) 32 val params = parseInto("export", args, options)
33 when (params.size) { 33 when (params.size) {
34 0 -> die("expecting CSV file name", 2) 34 0 -> throw SubcommandException(message = "expecting CSV file name", status = 2)
35 1 -> csvFile = params[0] 35 1 -> csvFile = params[0]
36 else -> die("unexpected trailing arguments", 2) 36 else -> throw SubcommandException(message = "unexpected trailing arguments", status = 2)
37 } 37 }
38 csvDateFormat = SimpleDateFormat(options.format).apply { 38 csvDateFormat = SimpleDateFormat(options.format).apply {
39 timeZone = TimeZone.getTimeZone(options.zone) 39 timeZone = TimeZone.getTimeZone(options.zone)
40 isLenient = false 40 isLenient = false
41 } 41 }