# HG changeset patch # User David Barts # Date 1720052062 25200 # Node ID 2188b2f133266b8f986f1ae9eca93097f8e8a8ec # Parent af86b8e0b88c7b838fe0cf060bcaba071f582dd5 Make some minor tweaks to the help system. diff -r af86b8e0b88c -r 2188b2f13326 src/main/kotlin/name/blackcap/passman/HelpSubcommand.kt --- a/src/main/kotlin/name/blackcap/passman/HelpSubcommand.kt Tue Jul 02 18:18:29 2024 -0700 +++ b/src/main/kotlin/name/blackcap/passman/HelpSubcommand.kt Wed Jul 03 17:14:22 2024 -0700 @@ -2,6 +2,14 @@ class HelpSubcommand(): Subcommand() { override fun run(args: Array) { + if (args.isEmpty() || args[0] == "-h" || args[0].startsWith("--h")) { + listSubcommands() + } else { + helpForSubcommand(args[0]) + } + } + + private fun listSubcommands() { println("PassMan: a password manager") println("Available subcommands:") println("create Create a new username/password pair.") @@ -19,4 +27,8 @@ println() println("Database is ${see(DB_FILE)} .") } + + private fun helpForSubcommand(subcom: String) { + runSubcommand(subcom, arrayOf("--help")) + } } diff -r af86b8e0b88c -r 2188b2f13326 src/main/kotlin/name/blackcap/passman/Main.kt --- a/src/main/kotlin/name/blackcap/passman/Main.kt Tue Jul 02 18:18:29 2024 -0700 +++ b/src/main/kotlin/name/blackcap/passman/Main.kt Wed Jul 03 17:14:22 2024 -0700 @@ -9,7 +9,7 @@ import kotlin.system.exitProcess fun main(args: Array) { - val NOPASSWORD = setOf("help") + val NOPASSWORD = setOf("help", "quit") if (args.isEmpty()) { openDatabase() runInteractive() @@ -48,6 +48,7 @@ val DISALLOWED = setOf("password") val QUIT = setOf("exit", "quit") var lastStatus = 0 + println("This is PassMan interactive mode. Type help for help.") while (true) { val rawLine = System.console()?.readLine("passman> ") if (rawLine == null) { diff -r af86b8e0b88c -r 2188b2f13326 src/main/kotlin/name/blackcap/passman/QuitSubcommand.kt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/kotlin/name/blackcap/passman/QuitSubcommand.kt Wed Jul 03 17:14:22 2024 -0700 @@ -0,0 +1,13 @@ +package name.blackcap.passman + +// This command does nothing except print a help message if requested, +// so that "help quit" works. The actual quit logic is hard-coded in +// Main.kt (and needs to be, so that exit status is correct). +class QuitSubcommand(): Subcommand() { + override fun run(args: Array) { + if (args.isNotEmpty() && (args[0] == "-h" || args[0].startsWith("--h"))) { + println("usage: passman quit [options]") + println(" -h,--help Print this help message.") + } + } +}