diff src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt @ 10:cbe4c797c9a6

Fix bug in parsing --length
author David Barts <n5jrn@me.com>
date Sat, 01 Oct 2022 20:43:59 -0700
parents 72619175004e
children 302d224bbd57
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt	Sat Oct 01 09:57:23 2022 -0700
+++ b/src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt	Sat Oct 01 20:43:59 2022 -0700
@@ -57,14 +57,15 @@
         db = Database.open()
         nameIn = commandLine.args[0]
         id = db.makeKey(nameIn)
-        length = commandLine.getOptionValue(LENGTH)?.let { rawLength ->
-            try {
-                rawLength.toInt()
-            } catch (e: NumberFormatException) {
-                die("${see(rawLength)} - invalid length")
-                -1  /* will never happen */
-            }
-        } ?: DEFAULT_GENERATED_LENGTH
+        val rawLength = commandLine.getOptionValue(LENGTH)
+        length = try {
+            rawLength?.toInt() ?: DEFAULT_GENERATED_LENGTH
+        } catch (e: NumberFormatException) {
+            -1
+        }
+        if (length < MIN_GENERATED_LENGTH) {
+            die("${see(rawLength)} - invalid length")
+        }
     }
 
     private fun checkArguments(): Unit {