20
20
/*
21
21
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
22
22
* Portions Copyright 2011 Jens Elkner.
23
- * Portions Copyright (c) 2017-2018 , Chris Fraire <[email protected] >.
23
+ * Portions Copyright (c) 2017-2019 , Chris Fraire <[email protected] >.
24
24
*/
25
25
package org .opengrok .indexer .index ;
26
26
@@ -92,6 +92,10 @@ public final class Indexer {
92
92
public static final char PATH_SEPARATOR ='/' ;
93
93
public static String PATH_SEPARATOR_STRING =Character .toString (PATH_SEPARATOR );
94
94
95
+ private static final String HELP_OPT_1 = "--help" ;
96
+ private static final String HELP_OPT_2 = "-?" ;
97
+ private static final String HELP_OPT_3 = "-h" ;
98
+
95
99
private static final Indexer index = new Indexer ();
96
100
private static Configuration cfg = null ;
97
101
private static boolean checkIndexVersion = false ;
@@ -402,7 +406,7 @@ public static WebAddress parseWebAddress(String webAddr) {
402
406
* @throws ParseException if parsing failed
403
407
*/
404
408
public static String [] parseOptions (String [] argv ) throws ParseException {
405
- String [] usage = {"--help" };
409
+ String [] usage = {HELP_OPT_1 };
406
410
String program = "opengrok.jar" ;
407
411
final String [] ON_OFF = {ON , OFF };
408
412
final String [] REMOTE_REPO_CHOICES = {ON , OFF , DIRBASED , UIONLY };
@@ -413,10 +417,19 @@ public static String[] parseOptions(String[] argv) throws ParseException {
413
417
status = 1 ;
414
418
}
415
419
420
+ /*
421
+ * Pre-match any of the --help options so that some possible exception-
422
+ * generating args handlers (e.g. -R) can be short-circuited.
423
+ */
424
+ help = Arrays .stream (argv ).anyMatch (s -> HELP_OPT_1 .equals (s ) ||
425
+ HELP_OPT_2 .equals (s ) || HELP_OPT_3 .equals (s ));
426
+
416
427
OptionParser configure = OptionParser .scan (parser -> {
417
428
parser .on ("-R configPath" ).Do (cfgFile -> {
418
429
try {
419
- cfg = Configuration .read (new File ((String )cfgFile ));
430
+ if (!help ) {
431
+ cfg = Configuration .read (new File ((String ) cfgFile ));
432
+ }
420
433
} catch (IOException e ) {
421
434
die (e .getMessage ());
422
435
}
@@ -430,7 +443,8 @@ public static String[] parseOptions(String[] argv) throws ParseException {
430
443
parser .setPrologue (
431
444
String .format ("\n Usage: java -jar %s [options] [subDir1 [...]]\n " , program ));
432
445
433
- parser .on ("-?" , "-h" , "--help" , "Display this usage summary." ).Do (v -> {
446
+ parser .on (HELP_OPT_3 , Indexer .HELP_OPT_2 , HELP_OPT_1 ,
447
+ "Display this usage summary." ).Do (v -> {
434
448
help = true ;
435
449
helpUsage = parser .getUsage ();
436
450
});
0 commit comments