changeset 13:302d224bbd57

Improve help messages and csv error reportage.
author David Barts <n5jrn@me.com>
date Tue, 24 Jan 2023 20:13:13 -0800
parents a38a2a1036c3
children 4dae7a15ee48
files src/main/kotlin/name/blackcap/passman/CreateSubcommand.kt src/main/kotlin/name/blackcap/passman/HelpSubcommand.kt src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt
diffstat 4 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/CreateSubcommand.kt	Sun Jan 22 09:22:53 2023 -0800
+++ b/src/main/kotlin/name/blackcap/passman/CreateSubcommand.kt	Tue Jan 24 20:13:13 2023 -0800
@@ -17,7 +17,7 @@
         val options = Options().apply {
             addOption("g", GENERATE, false, "Use password generator.")
             addOption("h", HELP, false, "Print this help message.")
-            addOption("l", LENGTH, true, "Length of generated password.")
+            addOption("l", LENGTH, true, "Length of generated password (default $DEFAULT_GENERATED_LENGTH).")
             addOption("s", SYMBOLS, false, "Use symbol characters in generated password.")
             addOption("v", VERBOSE, false, "Print the generated password.")
         }
--- a/src/main/kotlin/name/blackcap/passman/HelpSubcommand.kt	Sun Jan 22 09:22:53 2023 -0800
+++ b/src/main/kotlin/name/blackcap/passman/HelpSubcommand.kt	Tue Jan 24 20:13:13 2023 -0800
@@ -13,5 +13,7 @@
         println("read         Retrieve data from existing record.")
         println("rename       Rename existing record.")
         println("update       Update existing record.")
+        println()
+        println("Database is $DB_FILE .")
     }
 }
--- a/src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt	Sun Jan 22 09:22:53 2023 -0800
+++ b/src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt	Tue Jan 24 20:13:13 2023 -0800
@@ -2,6 +2,7 @@
 
 import com.opencsv.CSVParserBuilder
 import com.opencsv.CSVReaderBuilder
+import com.opencsv.exceptions.CsvException
 import org.apache.commons.cli.*
 import java.io.FileReader
 import java.io.IOException
@@ -33,6 +34,8 @@
     private var quote = '"'
     private var separator = ','
 
+    private var line = 0
+
     override fun run(args: Array<String>) {
         parseArguments(args)
         db = Database.open()
@@ -40,6 +43,9 @@
             doImport()
         } catch (e: IOException) {
             die(e.message ?: "I/O error")
+        } catch (e: CsvException) {
+            val message = e.message ?: "CSV error"
+            die("line $line, $message")
         }
     }
 
@@ -96,9 +102,12 @@
 
         csvReader.use {
             if (commandLine.hasOption(ImportSubcommand.SKIP)) {
+                line++
                 it.skip(1)
             }
+
             it.iterator().forEach { fields ->
+                line++
                 val importedEntry = fromCsv(fields)
                 val thisEntry = Entry.fromDatabase(db, importedEntry.name)
                 try {
@@ -118,7 +127,7 @@
 
     private fun fromCsv(fields: Array<String>): Entry {
         if (fields.size != NFIELDS) {
-            die("expected $NFIELDS fields but got ${fields.size}")
+            die("line $line, expected $NFIELDS fields but got ${fields.size}")
         }
         return Entry(
             name = fields[0],
@@ -148,4 +157,4 @@
 
     private fun saysNull(string: String) = string.lowercase() == "null"
 
-}
\ No newline at end of file
+}
--- a/src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt	Sun Jan 22 09:22:53 2023 -0800
+++ b/src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt	Tue Jan 24 20:13:13 2023 -0800
@@ -40,7 +40,7 @@
         val options = Options().apply {
             addOption("g", GENERATE, false, "Use password generator.")
             addOption("h", HELP, false, "Print this help message.")
-            addOption("l", LENGTH, true, "Length of generated password.")
+            addOption("l", LENGTH, true, "Length of generated password (default $DEFAULT_GENERATED_LENGTH).")
             addOption("s", SYMBOLS, false, "Use symbol characters in generated password.")
             addOption("v", VERBOSE, false, "Print the generated password.")
         }