Skip to content

Commit 5e426b1

Browse files
idodeclareVladimir Kotal
authored andcommitted
Specify a HelpMode to show various details
1 parent 68c19b4 commit 5e426b1

File tree

1 file changed

+37
-16
lines changed
  • opengrok-indexer/src/main/java/org/opengrok/indexer/index

1 file changed

+37
-16
lines changed

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

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@ public final class Indexer {
112112
private static boolean bareConfig = false;
113113
private static boolean awaitProfiler;
114114

115-
private static int help;
115+
private static boolean help;
116116
private static String helpUsage;
117+
private static HelpMode helpMode = HelpMode.DEFAULT;
117118

118119
private static String configFilename = null;
119120
private static int status = 0;
@@ -152,17 +153,24 @@ public static void main(String[] argv) {
152153

153154
try {
154155
argv = parseOptions(argv);
155-
if (help > 0) {
156+
if (help) {
156157
PrintStream helpStream = status != 0 ? System.err : System.out;
157-
helpStream.println(helpUsage);
158-
if (help > 1) {
159-
helpStream.println(AnalyzerGuruHelp.getUsage());
160-
helpStream.print(ConfigurationHelp.getSamples());
161-
}
162-
if (help > 2) {
163-
helpStream.println("Ctags command-line:");
164-
helpStream.println();
165-
helpStream.println(getCtagsCommand());
158+
switch (helpMode) {
159+
case CONFIG:
160+
helpStream.print(ConfigurationHelp.getSamples());
161+
break;
162+
case CTAGS:
163+
helpStream.println("Ctags command-line:");
164+
helpStream.println();
165+
helpStream.println(getCtagsCommand());
166+
helpStream.println();
167+
break;
168+
case GURU:
169+
helpStream.println(AnalyzerGuruHelp.getUsage());
170+
break;
171+
default:
172+
helpStream.println(helpUsage);
173+
break;
166174
}
167175
System.exit(status);
168176
}
@@ -436,12 +444,21 @@ public static String[] parseOptions(String[] argv) throws ParseException {
436444
parser.setPrologue(
437445
String.format("\nUsage: java -jar %s [options] [subDir1 [...]]\n", program));
438446

439-
parser.on(HELP_OPT_3, Indexer.HELP_OPT_2, HELP_OPT_1,
440-
"Display this usage summary.",
441-
" Repeat once for AnalyzerGuru details and configuration.xml samples.",
442-
" Repeat twice for ctags command-line.").Do(v -> {
443-
++help;
447+
parser.on(HELP_OPT_3, HELP_OPT_2, HELP_OPT_1, "=[mode]",
448+
"With no mode specified, display this usage summary. Or specify a mode:",
449+
" config - display configuration.xml examples.",
450+
" ctags - display ctags command-line.",
451+
" guru - display AnalyzerGuru details.").Do(v -> {
452+
help = true;
444453
helpUsage = parser.getUsage();
454+
String mode = (String) v;
455+
if (mode != null && !mode.isEmpty()) {
456+
try {
457+
helpMode = HelpMode.valueOf(((String) v).toUpperCase(Locale.ROOT));
458+
} catch (IllegalArgumentException ex) {
459+
die("mode '" + v + "' is not valid.");
460+
}
461+
}
445462
});
446463

447464
parser.on(
@@ -1131,6 +1148,10 @@ private static String getCtagsCommand() {
11311148
return Executor.escapeForShell(ctags.getArgv(), true, PlatformUtils.isWindows());
11321149
}
11331150

1151+
private enum HelpMode {
1152+
CONFIG, CTAGS, DEFAULT, GURU
1153+
}
1154+
11341155
private Indexer() {
11351156
}
11361157
}

0 commit comments

Comments
 (0)