comparison src/main/kotlin/name/blackcap/passman/Arguments.kt @ 21:ea65ab890f66

More work to support interactive feature.
author David Barts <n5jrn@me.com>
date Tue, 02 Jul 2024 11:27:39 -0700
parents 7a74ae668665
children 3a3067ba673b
comparison
equal deleted inserted replaced
20:4391afcf6bd0 21:ea65ab890f66
57 57
58 private fun doParse() { 58 private fun doParse() {
59 commandLine = try { 59 commandLine = try {
60 DefaultParser().parse(options, args) 60 DefaultParser().parse(options, args)
61 } catch (e: ParseException) { 61 } catch (e: ParseException) {
62 die(e.message ?: "syntax error", 2) 62 throw SubcommandException(message = e.message ?: "syntax error", status = 2)
63 throw RuntimeException("this will never happen")
64 } 63 }
65 if (commandLine.hasOption("help")) { 64 if (commandLine.hasOption("help")) {
66 HelpFormatter().printHelp("$SHORTNAME $name [options] csv_file", options) 65 HelpFormatter().printHelp("$SHORTNAME $name [options] csv_file", options)
67 exitProcess(0) 66 throw SubcommandException(status = 0)
68 } 67 }
69 } 68 }
70 69
71 private fun extract(): Array<String> { 70 private fun extract(): Array<String> {
72 annotated.iterate { annotated, info -> 71 annotated.iterate { annotated, info ->
90 } 89 }
91 90
92 private fun CommandLine.getCharOptionValue(name: String): Char { 91 private fun CommandLine.getCharOptionValue(name: String): Char {
93 val optionValue = getOptionValue(name) 92 val optionValue = getOptionValue(name)
94 when (optionValue.length) { 93 when (optionValue.length) {
95 0 -> die("--$name value must not be empty") 94 0 -> throw SubcommandException(message = "--$name value must not be empty")
96 1 -> return optionValue[0] 95 1 -> return optionValue[0]
97 else -> die("--$name value must be a single character") 96 else -> throw SubcommandException(message = "--$name value must be a single character")
98 } 97 }
99 throw RuntimeException("this will never happen")
100 } 98 }
101 } 99 }
102 100
103 fun parseInto(name: String, args: Array<String>, into: Any): Array<String> = 101 fun parseInto(name: String, args: Array<String>, into: Any): Array<String> =
104 AnnotationArgumentParser(name, args, into).parse() 102 AnnotationArgumentParser(name, args, into).parse()