Mercurial > cgi-bin > hgweb.cgi > PassMan
annotate src/main/kotlin/name/blackcap/passman/ListSubcommand.kt @ 28:287eadf5ab30 default tip
Check for timeouts inside subcommands while in interactive mode as well.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 31 Jul 2024 11:21:18 -0700 |
parents | 69526ae8c8de |
children |
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 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
6 class ListSubcommand(): Subcommand() { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
7 private companion object { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
8 const val CASE = "case" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
9 const val FIXED = "fixed" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
10 const val HELP = "help" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
11 const val LONG = "long" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
12 const val NAME = "name" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
13 const val NOTES = "notes" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
14 const val USERNAME = "username" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
15 const val ACCESSED = "accessed" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
16 const val CREATED = "created" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
17 const val MODIFIED = "modified" |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
18 val FLAG_OPTIONS = listOf<OptionDescriptor>( |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
19 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
|
20 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
|
21 OptionDescriptor(HELP, "Print this help message."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
22 OptionDescriptor(LONG, "Long format listing.") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
23 ) |
26
69526ae8c8de
Allow list --name to be abbreviated -n, since it is so commonly used.
David Barts <n5jrn@me.com>
parents:
22
diff
changeset
|
24 val ABBREV_STRING_OPTIONS = listOf<OptionDescriptor>( |
69526ae8c8de
Allow list --name to be abbreviated -n, since it is so commonly used.
David Barts <n5jrn@me.com>
parents:
22
diff
changeset
|
25 OptionDescriptor(NAME, "Match site name.") |
69526ae8c8de
Allow list --name to be abbreviated -n, since it is so commonly used.
David Barts <n5jrn@me.com>
parents:
22
diff
changeset
|
26 ) |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
27 val STRING_OPTIONS = listOf<OptionDescriptor>( |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
28 OptionDescriptor(NOTES, "Match notes."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
29 OptionDescriptor(USERNAME, "Match username.") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
30 ) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
31 val TIME_OPTIONS = listOf<OptionDescriptor>( |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
32 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
|
33 OptionDescriptor(CREATED, "Match time created."), |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
34 OptionDescriptor(MODIFIED, "Match time last modified.") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
35 ) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
36 val REDACTED = "(redacted)".toCharArray() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
37 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
38 private lateinit var commandLine: CommandLine |
7 | 39 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
|
40 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
41 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
|
42 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
43 override fun run(args: Array<String>) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
44 parseArgs(args) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
45 runQuery() |
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 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 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
|
49 val options = Options().apply { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
50 FLAG_OPTIONS.forEach { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
51 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
|
52 } |
26
69526ae8c8de
Allow list --name to be abbreviated -n, since it is so commonly used.
David Barts <n5jrn@me.com>
parents:
22
diff
changeset
|
53 ABBREV_STRING_OPTIONS.forEach() { |
69526ae8c8de
Allow list --name to be abbreviated -n, since it is so commonly used.
David Barts <n5jrn@me.com>
parents:
22
diff
changeset
|
54 addOption(Option(it.name.first().toString(), it.name, true, it.help).apply |
69526ae8c8de
Allow list --name to be abbreviated -n, since it is so commonly used.
David Barts <n5jrn@me.com>
parents:
22
diff
changeset
|
55 { setArgs(Option.UNLIMITED_VALUES) }) |
69526ae8c8de
Allow list --name to be abbreviated -n, since it is so commonly used.
David Barts <n5jrn@me.com>
parents:
22
diff
changeset
|
56 } |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
57 (STRING_OPTIONS + TIME_OPTIONS).forEach { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
58 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
|
59 { setArgs(Option.UNLIMITED_VALUES) }) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
60 } |
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 try { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
63 commandLine = DefaultParser().parse(options, args) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
64 } catch (e: ParseException) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
65 throw SubcommandException(message = e.message ?: "syntax error", cause = e, status = 2) |
6
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 if (commandLine.hasOption(HELP)) { |
9 | 68 HelpFormatter().printHelp("$SHORTNAME list [options]", options) |
22 | 69 throw SubcommandException(status = 0) |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
70 } |
8 | 71 if (commandLine.args.isNotEmpty()) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
72 throw SubcommandException(message = "unexpected trailing arguments", status = 2) |
8 | 73 } |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
74 |
26
69526ae8c8de
Allow list --name to be abbreviated -n, since it is so commonly used.
David Barts <n5jrn@me.com>
parents:
22
diff
changeset
|
75 (ABBREV_STRING_OPTIONS + STRING_OPTIONS).forEach { |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
76 commandLine.getOptionValues(it.name)?.forEach { value -> |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
77 val regexOptions = mutableSetOf<RegexOption>() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
78 if (commandLine.hasOption(FIXED)) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
79 regexOptions.add(RegexOption.LITERAL) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
80 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
81 if (!commandLine.hasOption(CASE)) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
82 regexOptions.add(RegexOption.IGNORE_CASE) |
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 try { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
85 if (it.name !in matchers) { |
7 | 86 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
|
87 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
88 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
|
89 } catch (e: PatternSyntaxException) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
90 throw SubcommandException(message = "${see(value)} - invalid regular expression", cause = e, status = 2) |
6
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 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
93 } |
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 TIME_OPTIONS.forEach { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
96 commandLine.getOptionValues(it.name)?.forEach { rawValue -> |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
97 if (rawValue.isEmpty()) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
98 throw SubcommandException(message = "empty string is not a valid time expression") |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
99 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
100 val (op, exp) = when(rawValue.first()) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
101 '+', '>' -> Pair<Char, String>('>', rawValue.substring(1)) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
102 '=' -> Pair<Char, String>('=', rawValue.substring(1)) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
103 '-', '<' -> Pair<Char, String>('<', rawValue.substring(1)) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
104 else -> Pair<Char, String>('=', rawValue) |
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 val value = parseDateTime(exp) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
107 if (value == null) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
108 throw SubcommandException(message = "${see(rawValue)} - invalid time expression") |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
109 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
110 if (it.name !in matchers) { |
7 | 111 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
|
112 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
113 when(op) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
114 '>' -> 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
|
115 '=' -> 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
|
116 '<' -> 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
|
117 else -> throw RuntimeException("should never happen") |
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 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
120 } |
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 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
123 private fun runQuery(): Unit { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
9
diff
changeset
|
124 val db = Database.default |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
125 |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
126 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
|
127 val results = it.executeQuery() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
128 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
|
129 var count = 0; |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
130 while (results.next()) { |
7 | 131 val entry = Entry( |
8 | 132 name = results.getDecryptedString(1, db.encryption)!!, |
133 username = results.getDecryptedString(2, db.encryption)!!, | |
7 | 134 password = REDACTED, |
135 notes = results.getDecryptedString(3, db.encryption), | |
136 created = results.getDate(4), | |
137 modified = results.getDate(5), | |
138 accessed = results.getDate(6) | |
139 ) | |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
140 val passed = matchers |
7 | 141 .map { x -> x.value.fold(true) { |
142 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
|
143 .reduceOrNull() { a, b -> a && b } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
144 ?: true |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
145 if (passed) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
146 if (count > 0) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
147 println() |
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 printer(entry, null) |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
150 count++ |
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 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
|
154 if (count > 0) { |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
155 println() |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
156 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
157 println("$count record$s found") |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
158 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
159 } |
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
160 } |