Mercurial > cgi-bin > hgweb.cgi > PassMan
diff src/main/kotlin/name/blackcap/passman/RenameSubcommand.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 | 0fc90892a3ae |
children |
line wrap: on
line diff
--- a/src/main/kotlin/name/blackcap/passman/RenameSubcommand.kt Sun Jun 30 22:28:52 2024 -0700 +++ b/src/main/kotlin/name/blackcap/passman/RenameSubcommand.kt Tue Jul 02 11:27:39 2024 -0700 @@ -1,9 +1,6 @@ package name.blackcap.passman import org.apache.commons.cli.* -import java.sql.PreparedStatement -import java.sql.Types -import kotlin.system.exitProcess class RenameSubcommand(): Subcommand() { private companion object { @@ -17,7 +14,10 @@ override fun run(args: Array<String>) { parseArguments(args) - db = Database.open() + if (commandLine.hasOption(HELP)) { + return + } + db = Database.default renameIt() } @@ -29,17 +29,17 @@ try { commandLine = DefaultParser().parse(options, args) } catch (e: ParseException) { - die(e.message ?: "syntax error", 2) + throw SubcommandException(message = e.message ?: "syntax error", status = 2, cause = e) } if (commandLine.hasOption(HELP)) { HelpFormatter().printHelp("$SHORTNAME rename [options] source destination", options) - exitProcess(0) + return } if (commandLine.args.size < 2) { - die("expecting source and destination", 2) + throw SubcommandException(message = "expecting source and destination", status = 2) } if (commandLine.args.size > 2) { - die("unexpected trailing arguments", 2) + throw SubcommandException(message = "unexpected trailing arguments", status = 2) } source = commandLine.args[0] destination = commandLine.args[1] @@ -50,13 +50,13 @@ val did = db.makeKey(destination) if(!recordExists(sid)) { - die("no record matches ${see(source)}") + throw SubcommandException(message = "no record matches ${see(source)}") } if (recordExists(did)) { if (commandLine.hasOption(FORCE)) { deleteRecord(did) } else { - die("record matching ${see(destination)} already exists") + throw SubcommandException(message = "record matching ${see(destination)} already exists") } }