Skip to content

Commit a4876aa

Browse files
committed
Short-circuit option -R if --help|-h|-? is used
1 parent 36334d3 commit a4876aa

File tree

1 file changed

+18
-4
lines changed
  • opengrok-indexer/src/main/java/org/opengrok/indexer/index

1 file changed

+18
-4
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/index/Indexer.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/*
2121
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2222
* 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]>.
2424
*/
2525
package org.opengrok.indexer.index;
2626

@@ -92,6 +92,10 @@ public final class Indexer {
9292
public static final char PATH_SEPARATOR ='/';
9393
public static String PATH_SEPARATOR_STRING =Character.toString(PATH_SEPARATOR);
9494

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+
9599
private static final Indexer index = new Indexer();
96100
private static Configuration cfg = null;
97101
private static boolean checkIndexVersion = false;
@@ -402,7 +406,7 @@ public static WebAddress parseWebAddress(String webAddr) {
402406
* @throws ParseException if parsing failed
403407
*/
404408
public static String[] parseOptions(String[] argv) throws ParseException {
405-
String[] usage = {"--help"};
409+
String[] usage = {HELP_OPT_1};
406410
String program = "opengrok.jar";
407411
final String[] ON_OFF = {ON, OFF};
408412
final String[] REMOTE_REPO_CHOICES = {ON, OFF, DIRBASED, UIONLY};
@@ -413,10 +417,19 @@ public static String[] parseOptions(String[] argv) throws ParseException {
413417
status = 1;
414418
}
415419

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+
416427
OptionParser configure = OptionParser.scan(parser -> {
417428
parser.on("-R configPath").Do(cfgFile -> {
418429
try {
419-
cfg = Configuration.read(new File((String)cfgFile));
430+
if (!help) {
431+
cfg = Configuration.read(new File((String) cfgFile));
432+
}
420433
} catch(IOException e) {
421434
die(e.getMessage());
422435
}
@@ -430,7 +443,8 @@ public static String[] parseOptions(String[] argv) throws ParseException {
430443
parser.setPrologue(
431444
String.format("\nUsage: java -jar %s [options] [subDir1 [...]]\n", program));
432445

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 -> {
434448
help = true;
435449
helpUsage = parser.getUsage();
436450
});

0 commit comments

Comments
 (0)