# HG changeset patch # User David Barts # Date 1674619993 28800 # Node ID 302d224bbd576c422a32193d8a5fe4268d988420 # Parent a38a2a1036c3f86f0ae3282b84dfe2ad50c810b5 Improve help messages and csv error reportage. diff -r a38a2a1036c3 -r 302d224bbd57 src/main/kotlin/name/blackcap/passman/CreateSubcommand.kt --- 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.") } diff -r a38a2a1036c3 -r 302d224bbd57 src/main/kotlin/name/blackcap/passman/HelpSubcommand.kt --- 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 .") } } diff -r a38a2a1036c3 -r 302d224bbd57 src/main/kotlin/name/blackcap/passman/ImportSubcommand.kt --- 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) { 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): 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 +} diff -r a38a2a1036c3 -r 302d224bbd57 src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt --- 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.") }