Mercurial > cgi-bin > hgweb.cgi > PassMan
diff src/main/kotlin/name/blackcap/passman/ReadSubcommand.kt @ 8:698c4a3d758d
Some code clean-up.
author | David Barts <n5jrn@me.com> |
---|---|
date | Fri, 23 Sep 2022 20:59:52 -0700 |
parents | 711cc42e96d7 |
children | 72619175004e |
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/ReadSubcommand.kt Tue Sep 20 21:54:32 2022 -0700 +++ b/src/main/kotlin/name/blackcap/passman/ReadSubcommand.kt Fri Sep 23 20:59:52 2022 -0700 @@ -4,25 +4,31 @@ import kotlin.system.exitProcess class ReadSubcommand(): Subcommand() { + private companion object { + const val CLIPBOARD = "clipboard" + const val HELP = "help" + const val LONG = "long" + const val ALT_SB = "\u001b[?1049h" + const val NORM_SB = "\u001b[?1049l" + const val CLEAR = "\u001b[H\u001b[2J" + } private lateinit var commandLine: CommandLine override fun run(args: Array<String>) { val options = Options().apply { - addOption("c", "clipboard", false, "Copy username and password into clipboard.") - addOption("h", "help", false, "Print this help message.") - addOption("l", "long", false, "Long format listing.") + addOption("c", CLIPBOARD, false, "Copy username and password into clipboard.") + addOption("h", HELP, false, "Print this help message.") + addOption("l", LONG, false, "Long format listing.") } try { commandLine = DefaultParser().parse(options, args) } catch (e: ParseException) { die(e.message ?: "syntax error", 2) } - if (commandLine.hasOption("help")) { + if (commandLine.hasOption(HELP)) { HelpFormatter().printHelp("$SHORTNAME read", options) exitProcess(0) } - val clipboard = commandLine.hasOption("clipboard") - val long = commandLine.hasOption("long") if (commandLine.args.isEmpty()) { error("expecting site name") } @@ -40,25 +46,28 @@ die("no record matches ${see(nameIn)}") } val entry = Entry( - name = result.getDecryptedString(1, db.encryption), - username = result.getDecryptedString(2, db.encryption), - password = result.getDecrypted(3, db.encryption), + name = result.getDecryptedString(1, db.encryption)!!, + username = result.getDecryptedString(2, db.encryption)!!, + password = result.getDecrypted(3, db.encryption)!!, notes = result.getDecryptedString(4, db.encryption), created = result.getDate(5), modified = result.getDate(6), accessed = result.getDate(7) ) try { - val redaction = if (clipboard) { "(in clipboard)" } else { null } - if (long) { + print(ALT_SB + CLEAR) + val redaction = if (commandLine.hasOption(CLIPBOARD)) { "(in clipboard)" } else { null } + if (commandLine.hasOption(LONG)) { entry.printLong(redaction) } else { entry.print(redaction) } - if (clipboard) { + if (commandLine.hasOption(CLIPBOARD)) { writeToClipboard(entry.password) } + name.blackcap.passman.readLine("Press ENTER to continue: ") } finally { + print(CLEAR + NORM_SB) entry.password.clear() } }