diff src/main/kotlin/name/blackcap/passman/ListSubcommand.kt @ 26:69526ae8c8de

Allow list --name to be abbreviated -n, since it is so commonly used.
author David Barts <n5jrn@me.com>
date Fri, 05 Jul 2024 10:11:31 -0700
parents 07406c4af4a5
children
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/ListSubcommand.kt	Thu Jul 04 09:49:36 2024 -0700
+++ b/src/main/kotlin/name/blackcap/passman/ListSubcommand.kt	Fri Jul 05 10:11:31 2024 -0700
@@ -21,8 +21,10 @@
             OptionDescriptor(HELP, "Print this help message."),
             OptionDescriptor(LONG, "Long format listing.")
         )
+        val ABBREV_STRING_OPTIONS = listOf<OptionDescriptor>(
+            OptionDescriptor(NAME, "Match site name.")
+        )
         val STRING_OPTIONS = listOf<OptionDescriptor>(
-            OptionDescriptor(NAME, "Match site name."),
             OptionDescriptor(NOTES, "Match notes."),
             OptionDescriptor(USERNAME, "Match username.")
         )
@@ -48,6 +50,10 @@
             FLAG_OPTIONS.forEach {
                 addOption(it.name.first().toString(), it.name, false, it.help)
             }
+            ABBREV_STRING_OPTIONS.forEach() {
+                addOption(Option(it.name.first().toString(), it.name, true, it.help).apply
+                    { setArgs(Option.UNLIMITED_VALUES) })
+            }
             (STRING_OPTIONS + TIME_OPTIONS).forEach {
                 addOption(Option(null, it.name, true, it.help).apply
                     { setArgs(Option.UNLIMITED_VALUES) })
@@ -66,7 +72,7 @@
             throw SubcommandException(message = "unexpected trailing arguments", status = 2)
         }
 
-        STRING_OPTIONS.forEach {
+        (ABBREV_STRING_OPTIONS + STRING_OPTIONS).forEach {
             commandLine.getOptionValues(it.name)?.forEach { value ->
                 val regexOptions = mutableSetOf<RegexOption>()
                 if (commandLine.hasOption(FIXED)) {