annotate src/main/kotlin/name/blackcap/passman/ListSubcommand.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 ea65ab890f66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
7
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
38 private val matchers = mutableMapOf<String, MutableList<(Any?) -> Boolean>>()
6
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)) {
9
72619175004e Fix issues found in testing.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
63 HelpFormatter().printHelp("$SHORTNAME list [options]", options)
6
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 }
8
698c4a3d758d Some code clean-up.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
66 if (commandLine.args.isNotEmpty()) {
9
72619175004e Fix issues found in testing.
David Barts <n5jrn@me.com>
parents: 8
diff changeset
67 die("unexpected trailing arguments", 2)
8
698c4a3d758d Some code clean-up.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
68 }
6
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
69
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
70 STRING_OPTIONS.forEach {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
71 commandLine.getOptionValues(it.name)?.forEach { value ->
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
72 val regexOptions = mutableSetOf<RegexOption>()
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
73 if (commandLine.hasOption(FIXED)) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
74 regexOptions.add(RegexOption.LITERAL)
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 if (!commandLine.hasOption(CASE)) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
77 regexOptions.add(RegexOption.IGNORE_CASE)
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
78 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
79 try {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
80 if (it.name !in matchers) {
7
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
81 matchers[it.name] = mutableListOf<(Any?) -> Boolean>()
6
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
82 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
83 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
84 } catch (e: PatternSyntaxException) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
85 die("${see(value)} - invalid regular expression")
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 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
88 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
89
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
90 TIME_OPTIONS.forEach {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
91 commandLine.getOptionValues(it.name)?.forEach { rawValue ->
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
92 if (rawValue.isEmpty()) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
93 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
94 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
95 val (op, exp) = when(rawValue.first()) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
96 '+', '>' -> Pair<Char, String>('>', rawValue.substring(1))
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
97 '=' -> Pair<Char, String>('=', rawValue.substring(1))
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
98 '-', '<' -> Pair<Char, String>('<', rawValue.substring(1))
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
99 else -> Pair<Char, String>('=', rawValue)
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
100 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
101 val value = parseDateTime(exp)
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
102 if (value == null) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
103 die("${see(rawValue)} - invalid time expression")
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
104 throw RuntimeException("will never happen")
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 if (it.name !in matchers) {
7
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
107 matchers[it.name] = mutableListOf<(Any?) -> Boolean>()
6
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
108 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
109 when(op) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
110 '>' -> 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
111 '=' -> 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
112 '<' -> 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
113 else -> throw RuntimeException("should never happen")
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 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
117 }
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 private fun runQuery(): Unit {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
120 val db = Database.open()
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
121
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
122 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
123 val results = it.executeQuery()
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
124 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
125 var count = 0;
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
126 while (results.next()) {
7
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
127 val entry = Entry(
8
698c4a3d758d Some code clean-up.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
128 name = results.getDecryptedString(1, db.encryption)!!,
698c4a3d758d Some code clean-up.
David Barts <n5jrn@me.com>
parents: 7
diff changeset
129 username = results.getDecryptedString(2, db.encryption)!!,
7
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
130 password = REDACTED,
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
131 notes = results.getDecryptedString(3, db.encryption),
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
132 created = results.getDate(4),
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
133 modified = results.getDate(5),
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
134 accessed = results.getDate(6)
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
135 )
6
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
136 val passed = matchers
7
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
137 .map { x -> x.value.fold(true) {
f245b9a53495 Efficiency improvements.
David Barts <n5jrn@me.com>
parents: 6
diff changeset
138 acc, pred -> acc && pred(entry.getField(x.key)) } }
6
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
139 .reduceOrNull() { a, b -> a && b }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
140 ?: true
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
141 if (passed) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
142 if (count > 0) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
143 println()
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 printer(entry, null)
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
146 count++
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
147 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
148 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
149 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
150 if (count > 0) {
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
151 println()
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 println("$count record$s found")
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 }
711cc42e96d7 Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff changeset
156 }