41
41
import picocli .CommandLine .Command ;
42
42
import picocli .CommandLine .IExecutionExceptionHandler ;
43
43
import picocli .CommandLine .IVersionProvider ;
44
+ import picocli .CommandLine .Mixin ;
44
45
import picocli .CommandLine .Option ;
45
46
import picocli .CommandLine .ParseResult ;
46
47
import picocli .CommandLine .ScopeType ;
@@ -68,17 +69,14 @@ public class Main extends ACommand {
68
69
69
70
public CommandLine commandLine = new CommandLine (this );
70
71
71
- @ Option (names = { "--keystore" },
72
- defaultValue = "${env:CONVEX_KEYSTORE:-" + Constants .KEYSTORE_FILENAME + "}" ,
73
- scope = ScopeType .INHERIT ,
74
- description = "Keystore filename. Default: ${DEFAULT-VALUE}" )
75
- private String keyStoreFilename ;
72
+ @ Mixin
73
+ private StoreMixin storeMixin ;
76
74
77
75
@ Option (names = { "-k" ,"--key" },
78
76
defaultValue = "${env:CONVEX_KEY}" ,
79
77
scope = ScopeType .INHERIT ,
80
78
description = "Public key to use. Default: ${DEFAULT-VALUE}" )
81
- private String keySpec ;
79
+ public String publicKey ;
82
80
83
81
@ Option (names = { "-p" ,"--keypass" },
84
82
defaultValue = "${env:CONVEX_KEY_PASSWORD}" ,
@@ -92,14 +90,7 @@ public class Main extends ACommand {
92
90
description = "Apply strict security. Will forbid actions with dubious security implications." )
93
91
private boolean paranoid ;
94
92
95
- /**
96
- * Password for keystore. Option named to match Java keytool
97
- */
98
- @ Option (names = {"--storepass" },
99
- scope = ScopeType .INHERIT ,
100
- defaultValue = "${env:CONVEX_KEYSTORE_PASSWORD}" ,
101
- description = "Password to read/write to the Keystore" )
102
- private String keystorePassword ;
93
+
103
94
104
95
@ Option (names = { "-n" ,"--noninteractive" },
105
96
scope = ScopeType .INHERIT ,
@@ -219,7 +210,7 @@ public int handleExecutionException(Exception ex, CommandLine commandLine, Parse
219
210
String msg =ce .getMessage ();
220
211
informError (msg );
221
212
Throwable cause = ce .getCause ();
222
- if ((verbose >=2 ) && (cause != null )) {
213
+ if ((verbose >=3 ) && (cause != null )) {
223
214
err .println ("Underlying cause: " );
224
215
cause .printStackTrace (err );
225
216
}
@@ -243,12 +234,12 @@ public int handleExecutionException(Exception ex, CommandLine commandLine, Parse
243
234
public char [] getStorePassword () {
244
235
char [] storepass = null ;
245
236
246
- if (this .keystorePassword != null ) {
247
- storepass = this .keystorePassword .toCharArray ();
237
+ if (storeMixin .keystorePassword != null ) {
238
+ storepass = storeMixin .keystorePassword .toCharArray ();
248
239
} else {
249
240
if (!nonInteractive ) {
250
241
storepass = readPassword ("Enter Keystore Password: " );
251
- keystorePassword =new String (storepass );
242
+ storeMixin . keystorePassword =new String (storepass );
252
243
}
253
244
254
245
if (storepass == null ) {
@@ -288,20 +279,9 @@ public char[] getKeyPassword() {
288
279
return keypass ;
289
280
}
290
281
291
- /**
292
- * Gets the keystore file name currently used for the CLI
293
- *
294
- * @return File name, or null if not specified
295
- */
296
- public File getKeyStoreFile () {
297
- if (keyStoreFilename != null ) {
298
- File f = Utils .getPath (keyStoreFilename );
299
- return f ;
300
- }
301
- return null ;
302
- }
303
282
304
- private KeyStore keyStore = null ;
283
+ KeyStore keyStore = null ;
284
+
305
285
306
286
/**
307
287
* Gets the current key store
@@ -331,7 +311,7 @@ public KeyStore loadKeyStore() {
331
311
* @return KeyStore instance, or null if does not exist
332
312
*/
333
313
public KeyStore loadKeyStore (boolean isCreate , char [] password ) {
334
- File keyFile = getKeyStoreFile ();
314
+ File keyFile = storeMixin . getKeyStoreFile ();
335
315
try {
336
316
if (keyFile .exists ()) {
337
317
keyStore = PFXTools .loadStore (keyFile , password );
@@ -373,7 +353,7 @@ public AKeyPair loadKeyFromStore(String publicKey) {
373
353
374
354
char [] storePassword = getStorePassword ();
375
355
376
- File keyFile = getKeyStoreFile ();
356
+ File keyFile = storeMixin . getKeyStoreFile ();
377
357
try {
378
358
if (!keyFile .exists ()) {
379
359
throw new CLIError ("Cannot find keystore file " + keyFile .getCanonicalPath ());
@@ -450,15 +430,15 @@ public void saveKeyStore(char[] storePassword) {
450
430
if (keyStore == null )
451
431
throw new CLIError ("Trying to save a keystore that has not been loaded!" );
452
432
try {
453
- PFXTools .saveStore (keyStore , getKeyStoreFile (), storePassword );
433
+ PFXTools .saveStore (keyStore , storeMixin . getKeyStoreFile (), storePassword );
454
434
} catch (Throwable t ) {
455
435
throw Utils .sneakyThrow (t );
456
436
}
457
437
}
458
438
459
439
public void saveKeyStore () {
460
- if (keystorePassword ==null ) throw new CLIError ("Key store password not provided" );
461
- saveKeyStore (keystorePassword .toCharArray ());
440
+ if (storeMixin . keystorePassword ==null ) throw new CLIError ("Key store password not provided" );
441
+ saveKeyStore (storeMixin . keystorePassword .toCharArray ());
462
442
}
463
443
464
444
public boolean isParanoid () {
0 commit comments