Mercurial > cgi-bin > hgweb.cgi > PassMan
annotate src/main/kotlin/name/blackcap/passman/ListSubcommand.kt @ 6:711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
author | David Barts <n5jrn@me.com> |
---|---|
date | Tue, 20 Sep 2022 20:52:21 -0700 |
parents | |
children | f245b9a53495 |
rev | line source |
---|---|
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
1 package name.blackcap.passman |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
2 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
3 import org.apache.commons.cli.* |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
4 import java.util.regex.PatternSyntaxException |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
5 import kotlin.system.exitProcess |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
6 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
7 class ListSubcommand(): Subcommand() { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
8 private companion object { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
9 const val CASE = "case" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
10 const val FIXED = "fixed" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
11 const val HELP = "help" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
12 const val LONG = "long" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
13 const val NAME = "name" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
14 const val NOTES = "notes" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
15 const val USERNAME = "username" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
16 const val ACCESSED = "accessed" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
17 const val CREATED = "created" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
18 const val MODIFIED = "modified" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
19 val FLAG_OPTIONS = listOf<OptionDescriptor>( |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
20 OptionDescriptor(CASE, "Treat upper and lower case as distinct."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
21 OptionDescriptor(FIXED, "Match fixed substrings instead of regular expressions."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
22 OptionDescriptor(HELP, "Print this help message."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
23 OptionDescriptor(LONG, "Long format listing.") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
24 ) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
25 val STRING_OPTIONS = listOf<OptionDescriptor>( |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
26 OptionDescriptor(NAME, "Match site name."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
27 OptionDescriptor(NOTES, "Match notes."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
28 OptionDescriptor(USERNAME, "Match username.") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
29 ) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
30 val TIME_OPTIONS = listOf<OptionDescriptor>( |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
31 OptionDescriptor(ACCESSED, "Match time password last read."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
32 OptionDescriptor(CREATED, "Match time created."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
33 OptionDescriptor(MODIFIED, "Match time last modified.") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
34 ) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
35 val REDACTED = "(redacted)".toCharArray() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
36 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
37 private lateinit var commandLine: CommandLine |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
38 private val matchers = mutableMapOf<String, MutableList<(Any) -> Boolean>>() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
39 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
40 private data class OptionDescriptor(val name: String, val help: String) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
41 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
42 override fun run(args: Array<String>) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
43 parseArgs(args) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
44 runQuery() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
45 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
46 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
47 private fun parseArgs(args: Array<String>): Unit { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 val options = Options().apply { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
49 FLAG_OPTIONS.forEach { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
50 addOption(it.name.first().toString(), it.name, false, it.help) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
51 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
52 (STRING_OPTIONS + TIME_OPTIONS).forEach { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
53 addOption(Option(null, it.name, true, it.help).apply |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
54 { setArgs(Option.UNLIMITED_VALUES) }) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
55 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
56 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
57 try { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
58 commandLine = DefaultParser().parse(options, args) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
59 } catch (e: ParseException) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
60 die(e.message ?: "syntax error", 2) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
61 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
62 if (commandLine.hasOption(HELP)) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
63 HelpFormatter().printHelp("$SHORTNAME list", options) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
64 exitProcess(0) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
65 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
66 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
67 STRING_OPTIONS.forEach { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
68 commandLine.getOptionValues(it.name)?.forEach { value -> |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
69 val regexOptions = mutableSetOf<RegexOption>() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
70 if (commandLine.hasOption(FIXED)) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
71 regexOptions.add(RegexOption.LITERAL) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
72 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
73 if (!commandLine.hasOption(CASE)) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
74 regexOptions.add(RegexOption.IGNORE_CASE) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
75 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
76 try { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
77 if (it.name !in matchers) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
78 matchers[it.name] = mutableListOf<(Any) -> Boolean>() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
79 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
80 matchers[it.name]!! += { x -> x is String && x.contains(Regex(value, regexOptions)) } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
81 } catch (e: PatternSyntaxException) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
82 die("${see(value)} - invalid regular expression") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
83 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
84 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
85 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
86 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
87 TIME_OPTIONS.forEach { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
88 commandLine.getOptionValues(it.name)?.forEach { rawValue -> |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
89 if (rawValue.isEmpty()) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
90 die("empty string is not a valid time expression") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
91 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
92 val (op, exp) = when(rawValue.first()) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
93 '+', '>' -> Pair<Char, String>('>', rawValue.substring(1)) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
94 '=' -> Pair<Char, String>('=', rawValue.substring(1)) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
95 '-', '<' -> Pair<Char, String>('<', rawValue.substring(1)) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
96 else -> Pair<Char, String>('=', rawValue) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
97 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
98 val value = parseDateTime(exp) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
99 if (value == null) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
100 die("${see(rawValue)} - invalid time expression") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
101 throw RuntimeException("will never happen") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
102 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
103 if (it.name !in matchers) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
104 matchers[it.name] = mutableListOf<(Any) -> Boolean>() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
105 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
106 when(op) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
107 '>' -> matchers[it.name]!! += { x -> x is Long && x > value } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
108 '=' -> matchers[it.name]!! += { x -> x is Long && (x/1000L) == (value/1000L) } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
109 '<' -> matchers[it.name]!! += { x -> x is Long && x < value } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
110 else -> throw RuntimeException("should never happen") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
111 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
112 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
113 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
114 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
115 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
116 private fun runQuery(): Unit { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
117 val db = Database.open() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
118 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
119 db.connection.prepareStatement("select $NAME, $USERNAME, $NOTES, $CREATED, $MODIFIED, $ACCESSED from passwords").use { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
120 val results = it.executeQuery() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
121 val printer = if (commandLine.hasOption(LONG)) Entry::printLong else Entry::print |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
122 var count = 0; |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
123 while (results.next()) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
124 val passed = matchers |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
125 .map { entry -> entry.value.fold(true) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
126 acc, pred -> acc && pred(results.getDecryptedString(entry.key, db.encryption)) } } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
127 .reduceOrNull() { a, b -> a && b } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
128 ?: true |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
129 if (passed) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
130 val entry = Entry( |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
131 name = results.getDecryptedString(1, db.encryption), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
132 username = results.getDecryptedString(2, db.encryption), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
133 password = REDACTED, |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
134 notes = results.getDecryptedString(3, db.encryption), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
135 created = results.getDate(4), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
136 modified = results.getDate(5), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
137 accessed = results.getDate(6) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
138 ) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
139 if (count > 0) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
140 println() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
141 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
142 printer(entry, null) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
143 count++ |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
144 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
145 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
146 val s = if (count == 1) "" else "s" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
147 if (count > 0) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
148 println() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
149 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
150 println("$count record$s found") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
151 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
152 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
153 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
154 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
155 private fun Options.addMultiOption(opt: String?, longOpt: String, hasArg: Boolean, description: String): Unit { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
156 addOption(Option(opt, longOpt, hasArg, description).apply { args = Option.UNLIMITED_VALUES }) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
157 } |