diff src/main/kotlin/name/blackcap/passman/MergeSubcommand.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 8f3ddebb4295
children
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/MergeSubcommand.kt	Sun Jun 30 22:28:52 2024 -0700
+++ b/src/main/kotlin/name/blackcap/passman/MergeSubcommand.kt	Tue Jul 02 11:27:39 2024 -0700
@@ -2,7 +2,6 @@
 
 import org.apache.commons.cli.*
 import java.sql.ResultSet
-import kotlin.system.exitProcess
 
 class MergeSubcommand(): Subcommand() {
     private companion object {
@@ -15,7 +14,10 @@
 
     override fun run(args: Array<String>) {
         parseArguments(args)
-        db = Database.open()
+        if (commandLine.hasOption(MergeSubcommand.HELP)) {
+            return
+        }
+        db = Database.default
         doMerge()
     }
 
@@ -28,17 +30,17 @@
         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(MergeSubcommand.HELP)) {
             HelpFormatter().printHelp("$SHORTNAME merge [options] other_database", options)
-            exitProcess(0)
+            return
         }
         if (commandLine.args.isEmpty()) {
-            die("expecting other database name", 2)
+            throw SubcommandException(message = "expecting other database name", status = 2)
         }
         if (commandLine.args.size > 1) {
-            die("unexpected trailing arguments", 2)
+            throw SubcommandException(message = "unexpected trailing arguments", status = 2)
         }
     }