diff src/main/kotlin/name/blackcap/passman/ReadSubcommand.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 a38a2a1036c3
children 131e39d96862
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/ReadSubcommand.kt	Sun Jun 30 22:28:52 2024 -0700
+++ b/src/main/kotlin/name/blackcap/passman/ReadSubcommand.kt	Tue Jul 02 11:27:39 2024 -0700
@@ -1,7 +1,6 @@
 package name.blackcap.passman
 
 import org.apache.commons.cli.*
-import kotlin.system.exitProcess
 
 class ReadSubcommand(): Subcommand() {
     private companion object {
@@ -23,24 +22,23 @@
         try {
             commandLine = DefaultParser().parse(options, args)
         } catch (e: ParseException) {
-            die(e.message ?: "syntax error", 2)
+            throw SubcommandException(message = e.message ?: "syntax error", status = 2, cause = e)
         }
         if (commandLine.hasOption(HELP)) {
             HelpFormatter().printHelp("$SHORTNAME read [options] name", options)
-            exitProcess(0)
+            return
         }
         if (commandLine.args.isEmpty()) {
-            die("expecting site name", 2)
+            throw SubcommandException(message = "expecting site name", status = 2)
         }
         if (commandLine.args.size > 1) {
-            die("unexpected trailing arguments", 2)
+            throw SubcommandException(message = "unexpected trailing arguments", status = 2)
         }
         val nameIn = commandLine.args[0];
-        val db = Database.open()
+        val db = Database.default
         val entry = Entry.fromDatabase(db, nameIn)
         if (entry == null) {
-            die("no record matches ${see(nameIn)}")
-            return // Kotlin is too stupid to realize we never get here
+            throw SubcommandException(message = "no record matches ${see(nameIn)}")
         }
         try {
             print(ALT_SB + CLEAR)