Mercurial > cgi-bin > hgweb.cgi > PassMan
diff src/main/kotlin/name/blackcap/passman/ReadSubcommand.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 | eafa3779aef8 |
children | 698c4a3d758d |
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/ReadSubcommand.kt Sun Sep 11 21:29:20 2022 -0700 +++ b/src/main/kotlin/name/blackcap/passman/ReadSubcommand.kt Tue Sep 20 20:52:21 2022 -0700 @@ -1,9 +1,7 @@ package name.blackcap.passman -import org.apache.commons.cli.CommandLine -import org.apache.commons.cli.DefaultParser -import org.apache.commons.cli.Options -import org.apache.commons.cli.ParseException +import org.apache.commons.cli.* +import kotlin.system.exitProcess class ReadSubcommand(): Subcommand() { private lateinit var commandLine: CommandLine @@ -11,6 +9,7 @@ override fun run(args: Array<String>) { val options = Options().apply { addOption("c", "clipboard", false, "Copy username and password into clipboard.") + addOption("h", "help", false, "Print this help message.") addOption("l", "long", false, "Long format listing.") } try { @@ -18,10 +17,17 @@ } catch (e: ParseException) { die(e.message ?: "syntax error", 2) } + if (commandLine.hasOption("help")) { + HelpFormatter().printHelp("$SHORTNAME read", options) + exitProcess(0) + } val clipboard = commandLine.hasOption("clipboard") val long = commandLine.hasOption("long") - if (commandLine.args.size != 1) { - die("expecting site name", 2) + if (commandLine.args.isEmpty()) { + error("expecting site name") + } + if (commandLine.args.size > 1) { + error("unexpected trailing arguments") } val nameIn = commandLine.args[0]; val db = Database.open()