@@ -112,8 +112,9 @@ public final class Indexer {
112
112
private static boolean bareConfig = false ;
113
113
private static boolean awaitProfiler ;
114
114
115
- private static int help ;
115
+ private static boolean help ;
116
116
private static String helpUsage ;
117
+ private static HelpMode helpMode = HelpMode .DEFAULT ;
117
118
118
119
private static String configFilename = null ;
119
120
private static int status = 0 ;
@@ -152,17 +153,24 @@ public static void main(String[] argv) {
152
153
153
154
try {
154
155
argv = parseOptions (argv );
155
- if (help > 0 ) {
156
+ if (help ) {
156
157
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 ;
166
174
}
167
175
System .exit (status );
168
176
}
@@ -436,12 +444,21 @@ public static String[] parseOptions(String[] argv) throws ParseException {
436
444
parser .setPrologue (
437
445
String .format ("\n Usage: java -jar %s [options] [subDir1 [...]]\n " , program ));
438
446
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 ;
444
453
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
+ }
445
462
});
446
463
447
464
parser .on (
@@ -1131,6 +1148,10 @@ private static String getCtagsCommand() {
1131
1148
return Executor .escapeForShell (ctags .getArgv (), true , PlatformUtils .isWindows ());
1132
1149
}
1133
1150
1151
+ private enum HelpMode {
1152
+ CONFIG , CTAGS , DEFAULT , GURU
1153
+ }
1154
+
1134
1155
private Indexer () {
1135
1156
}
1136
1157
}
0 commit comments