Mercurial > cgi-bin > hgweb.cgi > PassMan
comparison src/main/kotlin/name/blackcap/passman/UpdateSubcommand.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 |
comparison
equal
deleted
inserted
replaced
5:ad997df1f560 | 6:711cc42e96d7 |
---|---|
1 package name.blackcap.passman | 1 package name.blackcap.passman |
2 | 2 |
3 import org.apache.commons.cli.CommandLine | 3 import org.apache.commons.cli.* |
4 import org.apache.commons.cli.DefaultParser | |
5 import org.apache.commons.cli.Options | |
6 import org.apache.commons.cli.ParseException | |
7 import java.sql.Types | 4 import java.sql.Types |
8 import java.util.* | 5 import java.util.* |
9 import kotlin.properties.Delegates | 6 import kotlin.properties.Delegates |
10 import kotlin.system.exitProcess | 7 import kotlin.system.exitProcess |
11 | 8 |
34 } | 31 } |
35 | 32 |
36 private fun parseArguments(args: Array<String>) { | 33 private fun parseArguments(args: Array<String>) { |
37 val options = Options().apply { | 34 val options = Options().apply { |
38 addOption("g", "generate", false, "Use password generator.") | 35 addOption("g", "generate", false, "Use password generator.") |
36 addOption("h", "help", false, "Print this help message.") | |
39 addOption("l", "length", true, "Length of generated password.") | 37 addOption("l", "length", true, "Length of generated password.") |
40 addOption("s", "symbols", false, "Use symbol characters in generated password.") | 38 addOption("s", "symbols", false, "Use symbol characters in generated password.") |
41 addOption("v", "verbose", false, "Print the generated password.") | 39 addOption("v", "verbose", false, "Print the generated password.") |
42 } | 40 } |
43 try { | 41 try { |
44 commandLine = DefaultParser().parse(options, args) | 42 commandLine = DefaultParser().parse(options, args) |
45 } catch (e: ParseException) { | 43 } catch (e: ParseException) { |
46 die(e.message ?: "syntax error", 2) | 44 die(e.message ?: "syntax error", 2) |
45 } | |
46 if (commandLine.hasOption("help")) { | |
47 HelpFormatter().printHelp("$SHORTNAME update", options) | |
48 exitProcess(0) | |
47 } | 49 } |
48 checkArguments() | 50 checkArguments() |
49 db = Database.open() | 51 db = Database.open() |
50 nameIn = commandLine.args[0] | 52 nameIn = commandLine.args[0] |
51 id = db.makeKey(nameIn) | 53 id = db.makeKey(nameIn) |