Mercurial > cgi-bin > hgweb.cgi > PassMan
annotate src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt @ 28:287eadf5ab30 default tip
Check for timeouts inside subcommands while in interactive mode as well.
author | David Barts <n5jrn@me.com> |
---|---|
date | Wed, 31 Jul 2024 11:21:18 -0700 |
parents | ea65ab890f66 |
children |
rev | line source |
---|---|
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
1 package name.blackcap.passman |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
2 |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
3 import org.apache.commons.cli.* |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
4 import java.sql.Types |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
5 import java.util.* |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
6 import kotlin.properties.Delegates |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
7 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
8 class UpdateSubcommand(): Subcommand() { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
9 private lateinit var commandLine: CommandLine |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
10 private lateinit var db: Database |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
11 private lateinit var nameIn: String |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
12 private var id by Delegates.notNull<Long>() |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
13 private var length by Delegates.notNull<Int>() |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
14 private val fields = StringBuilder() |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
15 private val fieldValues = mutableListOf<Any?>() |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
16 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
17 private companion object { |
8 | 18 const val GENERATE = "generate" |
19 const val HELP = "help" | |
20 const val LENGTH = "length" | |
21 const val SYMBOLS = "symbols" | |
22 const val VERBOSE = "verbose" | |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
23 const val NULL_SPECIFIED = "." |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
24 val NULLABLE_FIELDS = setOf<String>("notes") |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
25 val SENSITIVE_FIELDS = setOf<String>("password") |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
26 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
27 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
28 override fun run(args: Array<String>) { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
29 parseArguments(args) |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
30 if (commandLine.hasOption(HELP)) { |
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
31 return |
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
32 } |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
33 checkDatabase() |
8 | 34 try { |
35 update() | |
36 } finally { | |
37 cleanUp() | |
38 } | |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
39 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
40 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
41 private fun parseArguments(args: Array<String>) { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
42 val options = Options().apply { |
8 | 43 addOption("g", GENERATE, false, "Use password generator.") |
44 addOption("h", HELP, false, "Print this help message.") | |
13
302d224bbd57
Improve help messages and csv error reportage.
David Barts <n5jrn@me.com>
parents:
10
diff
changeset
|
45 addOption("l", LENGTH, true, "Length of generated password (default $DEFAULT_GENERATED_LENGTH).") |
8 | 46 addOption("s", SYMBOLS, false, "Use symbol characters in generated password.") |
47 addOption("v", VERBOSE, false, "Print the generated password.") | |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
48 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
49 try { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
50 commandLine = DefaultParser().parse(options, args) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
51 } catch (e: ParseException) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
52 throw SubcommandException(message = e.message ?: "syntax error", status = 2, cause = e) |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
53 } |
8 | 54 if (commandLine.hasOption(HELP)) { |
9 | 55 HelpFormatter().printHelp("$SHORTNAME update [options] name", options) |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
56 return |
6
711cc42e96d7
Got the list subcommand working, but needs efficiency improvements.
David Barts <n5jrn@me.com>
parents:
3
diff
changeset
|
57 } |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
58 checkArguments() |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
59 db = Database.default |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
60 nameIn = commandLine.args[0] |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
61 id = db.makeKey(nameIn) |
10 | 62 val rawLength = commandLine.getOptionValue(LENGTH) |
63 length = try { | |
64 rawLength?.toInt() ?: DEFAULT_GENERATED_LENGTH | |
65 } catch (e: NumberFormatException) { | |
66 -1 | |
67 } | |
68 if (length < MIN_GENERATED_LENGTH) { | |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
69 throw SubcommandException(message = "${see(rawLength)} - invalid length") |
10 | 70 } |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
71 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
72 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
73 private fun checkArguments(): Unit { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
74 var bad = false |
8 | 75 if (!commandLine.hasOption(GENERATE)) { |
76 for (option in listOf<String>(LENGTH, SYMBOLS, VERBOSE)) { | |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
77 if (commandLine.hasOption(option)) { |
8 | 78 error("--$option requires --$GENERATE") |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
79 bad = true |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
80 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
81 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
82 } |
9 | 83 if (bad) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
84 throw SubcommandException(status = 2) |
9 | 85 } |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
86 if (commandLine.args.isEmpty()) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
87 throw SubcommandException(message = "expecting site name", status = 2) |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
88 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
89 if (commandLine.args.size > 1) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
90 throw SubcommandException(message = "unexpected trailing arguments", status = 2) |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
91 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
92 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
93 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
94 private fun checkDatabase(): Unit { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
95 db.connection.prepareStatement("select count(*) from passwords where id = ?").use { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
96 it.setLong(1, id) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
97 val result = it.executeQuery() |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
98 result.next() |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
99 val count = result.getInt(1) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
100 if (count < 1) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
101 throw SubcommandException(message = "no record matches " + see(nameIn)) |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
102 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
103 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
104 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
105 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
106 private fun update(): Unit { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
107 updateOne("username") |
8 | 108 if (commandLine.hasOption(GENERATE)) { |
2
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
109 generatePassword() |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
110 } else { |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
111 updateOne("password") |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
112 } |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
113 updateOne("notes") |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
114 if (fieldValues.isEmpty()) { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
115 error("no values changed") |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
116 return |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
117 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
118 |
2
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
119 db.connection.prepareStatement("update passwords set modified = ?, $fields where id = ?").use { stmt -> |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
120 stmt.setLong(1, System.currentTimeMillis()) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
121 fieldValues.indices.forEach { fieldIndex -> |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
122 val fieldValue = fieldValues[fieldIndex] |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
123 val columnIndex = fieldIndex + 2 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
124 when (fieldValue) { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
125 is String -> stmt.setEncryptedString(columnIndex, fieldValue, db.encryption) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
126 is CharArray -> stmt.setEncrypted(columnIndex, fieldValue, db.encryption) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
127 null -> stmt.setNull(columnIndex, Types.BLOB) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
128 else -> throw RuntimeException("this shouldn't happen") |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
129 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
130 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
131 stmt.setLong(fieldValues.size + 2, id) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
132 stmt.execute() |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
133 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
134 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
135 |
8 | 136 private fun cleanUp(): Unit { |
9 | 137 fieldValues.forEach { |
138 if (it is CharArray) { | |
139 it.clear() | |
140 } | |
141 } | |
8 | 142 } |
143 | |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
144 private fun updateOne(name: String): Unit { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
145 val prompt = name.replaceFirstChar { it.uppercase(Locale.getDefault()) } + ": " |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
146 val value: Any? = if (name in SENSITIVE_FIELDS) { |
21
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
147 try { |
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
148 getPassword(prompt) |
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
149 } catch (e: ConsoleException) { |
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
150 throw SubcommandException(message = e.message, cause = e) |
ea65ab890f66
More work to support interactive feature.
David Barts <n5jrn@me.com>
parents:
13
diff
changeset
|
151 } |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
152 } else { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
153 val rawValue = readLine(prompt) |
2
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
154 if (name in NULLABLE_FIELDS && rawValue == NULL_SPECIFIED) { |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
155 null |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
156 } else { |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
157 rawValue |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
158 } |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
159 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
160 |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
161 val noChange = when (value) { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
162 is String -> value.isEmpty() |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
163 is CharArray -> value.isEmpty() |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
164 else -> false |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
165 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
166 if (noChange) { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
167 return |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
168 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
169 |
2
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
170 addOne(name, value) |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
171 } |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
172 |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
173 private fun addOne(name: String, value: Any?) { |
0
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
174 if (fields.isNotEmpty()) { |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
175 fields.append(", ") |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
176 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
177 fields.append(name) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
178 fields.append(" = ?") |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
179 fieldValues.add(value) |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
180 } |
a6cfdffcaa94
Initial commit, incomplete but it runs sorta.
David Barts <n5jrn@me.com>
parents:
diff
changeset
|
181 |
2
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
182 private fun generatePassword(): Unit { |
8 | 183 val newPassword = generate(length, commandLine.hasOption(SYMBOLS)) |
184 if (commandLine.hasOption(VERBOSE)) { | |
2
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
185 printPassword(newPassword) |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
186 } |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
187 addOne("password", newPassword) |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
188 } |
3c792ad36b3d
Can now update a password and read it back.
David Barts <n5jrn@me.com>
parents:
0
diff
changeset
|
189 |
3
eafa3779aef8
More bug fixes, quote strings in diagnostics.
David Barts <n5jrn@me.com>
parents:
2
diff
changeset
|
190 } |