Skip to content

Commit 5d6ffbc

Browse files
committed
Fix up some Indexer docs, and update for clarity
Also, require option descriptions to be at the tail of Option.on() so that description lines (after the first) that start with -, --, =, or / are not confusingly parsed as option specs.
1 parent a483cb1 commit 5d6ffbc

File tree

2 files changed

+55
-57
lines changed

2 files changed

+55
-57
lines changed

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

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
461461
"Files with the named prefix/extension should be analyzed",
462462
"with the given analyzer, where 'analyzer' may be specified",
463463
"using a simple class name (RubyAnalyzer) or language name (C)",
464-
"(Note, analyzer specification is case sensitive)",
464+
"(Note, analyzer specification is case-sensitive)",
465465
" Ex: -A .foo:CAnalyzer",
466466
" will use the C analyzer for all files ending with .FOO",
467467
" Ex: -A bar.:Perl",
@@ -528,11 +528,9 @@ public static String[] parseOptions(String[] argv) throws ParseException {
528528
});
529529

530530
parser.on("-e", "--economical",
531-
"Economical, consumes less disk space.",
532-
"It does not generate hyper text cross reference files offline,",
533-
"but will do so on demand, which could be sightly slow.").Do(v -> {
534-
cfg.setGenerateHtml(false);
535-
});
531+
"To consume less disk space, OpenGrok will not generate and save",
532+
"hypertext cross-reference files but will generate on demand, which could",
533+
"be slightly slow.").Do(v -> cfg.setGenerateHtml(false));
536534

537535
parser.on("-G", "--assignTags",
538536
"Assign commit tags to all entries in history for all repositories.").Do(v -> {
@@ -544,17 +542,15 @@ public static String[] parseOptions(String[] argv) throws ParseException {
544542
});
545543

546544
parser.on("-I", "--include", "=pattern",
547-
"Only files matching this pattern will be examined.",
548-
"(supports wildcards, example: -I *.java -I *.c)").Do(pattern -> {
549-
cfg.getIncludedNames().add((String) pattern);
550-
});
545+
"Only files matching this pattern will be examined. Pattern supports",
546+
"wildcards (example: -I '*.java' -I '*.c'). Option may be repeated.").Do(
547+
pattern -> cfg.getIncludedNames().add((String) pattern));
551548

552549
parser.on("-i", "--ignore", "=pattern",
553-
"Ignore the named files (prefixed with 'f:')",
554-
"or directories (prefixed with 'd:').",
555-
"Supports wildcards (example: -i *.so -i *.dll)").Do(pattern -> {
556-
cfg.getIgnoredNames().add((String) pattern);
557-
});
550+
"Ignore matching files (prefixed with 'f:' or no prefix) or directories",
551+
"(prefixed with 'd:'). Pattern supports wildcards (example: -i '*.so'",
552+
"-i d:'test*'). Option may be repeated.").Do(pattern ->
553+
cfg.getIgnoredNames().add((String) pattern));
558554

559555
parser.on("-l", "--lock", "=on|off|simple|native", LUCENE_LOCKS,
560556
"Set OpenGrok/Lucene locking mode of the Lucene database",
@@ -577,11 +573,11 @@ public static String[] parseOptions(String[] argv) throws ParseException {
577573
});
578574

579575
parser.on("-m", "--memory", "=number", Double.class,
580-
"Amount of memory that may be used for buffering added documents and",
581-
"deletions before they are flushed to the directory (default " + Configuration.defaultRamBufferSize + "MB).",
582-
"Please increase JVM heap accordingly, too.").Do(memSize -> {
583-
cfg.setRamBufferSize((Double) memSize);
584-
});
576+
"Amount of memory (MB) that may be used for buffering added documents and",
577+
"deletions before they are flushed to the directory (default " +
578+
Configuration.defaultRamBufferSize + ").",
579+
"Please increase JVM heap accordingly too.").Do(memSize ->
580+
cfg.setRamBufferSize((Double) memSize));
585581

586582
parser.on("--man", "Generate OpenGrok XML manual page.").Do(v -> {
587583
try {
@@ -604,9 +600,9 @@ public static String[] parseOptions(String[] argv) throws ParseException {
604600
allowedSymlinks.add((String) v));
605601

606602
parser.on("-n", "--noIndex",
607-
"Do not generate indexes and other data (such as history cache",
608-
"and xref files), but process all other command line options.").Do(v ->
609-
runIndex = false);
603+
"Do not generate indexes and other data (such as history cache and xref",
604+
"files), but process all other command line options.").Do(v ->
605+
runIndex = false);
610606

611607
parser.on("-O", "--optimize", "=on|off", ON_OFF, Boolean.class,
612608
"Turn on/off the optimization of the index database",
@@ -640,42 +636,37 @@ public static String[] parseOptions(String[] argv) throws ParseException {
640636
cfg.setProjectsEnabled(true);
641637
});
642638

643-
parser.on("-p", "--defaultProject", "=/path/to/default/project",
644-
"This is the path to the project that should be selected",
645-
"by default in the web application (when no other project",
646-
"set either in cookie or in parameter). Option may be repeated",
647-
"to specify several projects. Use \"__all__\" for all projects.",
648-
"You should strip off the source root.").Do(v -> {
649-
defaultProjects.add((String) v);
650-
});
639+
parser.on("-p", "--defaultProject", "=path/to/default/project",
640+
"Path (relative to the source root) to a project that should be selected",
641+
"by default in the web application (when no other project is set either",
642+
"in a cookie or in parameter). Option may be repeated to specify several",
643+
"projects. Use the special value __all__ to indicate all projects.").Do(v ->
644+
defaultProjects.add((String) v));
651645

652646
parser.on("--profiler", "Pause to await profiler or debugger.").
653647
Do(v -> awaitProfiler = true);
654648

655649
parser.on("--progress",
656-
"Print per project percentage progress information.",
657-
"(I/O extensive, since one read through directory structure is",
658-
"made before indexing, needs -v, otherwise it just goes to the log)").
659-
Do(v -> cfg.setPrintProgress(true)
660-
);
650+
"Print per-project percentage progress information.").Do(v ->
651+
cfg.setPrintProgress(true));
661652

662653
parser.on("-Q", "--quickScan", "=on|off", ON_OFF, Boolean.class,
663-
"Turn on/off quick context scan. By default, only the first",
664-
"1024k of a file is scanned, and a '[..all..]' link is inserted",
665-
"when the file is bigger. Activating this may slow the server down.",
666-
"(Note: this is setting only affects the web application)").Do(v -> {
667-
cfg.setQuickContextScan((Boolean) v);
668-
});
654+
"Turn on/off quick context scan. By default, only the first 1024KB of a",
655+
"file is scanned, and a link ('[..all..]') is inserted when the file is",
656+
"bigger. Activating this may slow the server down. (Note: this setting",
657+
"only affects the web application.)").Do(v ->
658+
cfg.setQuickContextScan((Boolean) v));
669659

670660
parser.on("-q", "--quiet", "Run as quietly as possible.",
671661
"Sets logging level to WARNING.").Do(v -> {
672662
LoggerUtil.setBaseConsoleLogLevel(Level.WARNING);
673663
});
674664

675-
parser.on("--repository", "=repository",
676-
"Generate history for specific repository specified as relative",
677-
"path to source root. Assumes -H,--history is on. Option may be",
678-
"repeated.").Do(v -> repositories.add((String) v));
665+
parser.on("--repository", "=path/to/repository",
666+
"Path (relative to the source root) to a repository for generating",
667+
"history (if -H,--history is on). By default all discovered repositories",
668+
"are history-eligible; using --repository limits to only those specified.",
669+
"Option may be repeated.").Do(v -> repositories.add((String) v));
679670

680671
parser.on("-R /path/to/configuration",
681672
"Read configuration from the specified file.").Do(v -> {
@@ -710,7 +701,8 @@ public static String[] parseOptions(String[] argv) throws ParseException {
710701
"with lots of renamed files.").Do(v -> cfg.setHandleHistoryOfRenamedFiles((Boolean) v));
711702

712703
parser.on("-S", "--search",
713-
"Search for \"external\" source repositories and add them.").Do(v -> searchRepositories = true);
704+
"Search for source repositories under -s,--source, and add them.").Do(v ->
705+
searchRepositories = true);
714706

715707
parser.on("-s", "--source", "=/path/to/source/root",
716708
"The root directory of the source tree.").
@@ -728,10 +720,9 @@ public static String[] parseOptions(String[] argv) throws ParseException {
728720
);
729721

730722
parser.on("--style", "=path",
731-
"Path to the subdirectory in the web-application containing the",
732-
"requested stylesheet. The factory-setting is: \"default\".").
733-
Do(stylePath -> cfg.setWebappLAF((String) stylePath)
734-
);
723+
"Path to the subdirectory in the web application containing the requested",
724+
"stylesheet. The factory-setting is: \"default\".").Do(stylePath ->
725+
cfg.setWebappLAF((String) stylePath));
735726

736727
parser.on("-T", "--threads", "=number", Integer.class,
737728
"The number of threads to use for index generation.",
@@ -742,7 +733,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
742733
"Default tab size to use (number of spaces per tab character).")
743734
.Do(tabSize -> cfg.setTabSize((Integer) tabSize));
744735

745-
parser.on("-U", "--uri", "=protocol://webappURI:port/contextPath",
736+
parser.on("-U", "--uri", "=SCHEME://webappURI:port/contextPath",
746737
"Send the current configuration to the specified webappURI").Do(webAddr -> {
747738
webappURI = (String) webAddr;
748739
try {
@@ -763,8 +754,8 @@ public static String[] parseOptions(String[] argv) throws ParseException {
763754
parser.on("---unitTest"); // For unit test only, will not appear in help
764755

765756
parser.on("--updateConfig",
766-
"Populate the webapp with bare configuration and exit.")
767-
.Do(v -> bareConfig = true);
757+
"Populate the webapp with bare configuration, and exit.").Do(v ->
758+
bareConfig = true);
768759

769760
parser.on("--userPage", "=URL",
770761
"Base URL of the user Information provider.",
@@ -775,7 +766,7 @@ public static String[] parseOptions(String[] argv) throws ParseException {
775766
"URL Suffix for the user Information provider. Default: \"\".")
776767
.Do(suffix -> cfg.setUserPageSuffix((String) suffix));
777768

778-
parser.on("-V", "--version", "Print version and quit.").Do(v -> {
769+
parser.on("-V", "--version", "Print version, and quit.").Do(v -> {
779770
System.out.println(Info.getFullVersion());
780771
System.exit(0);
781772
});

opengrok-indexer/src/main/java/org/opengrok/indexer/util/OptionParser.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
/*
2121
* Portions Copyright (c) 2017, Steven Haehn.
22+
* Portions Copyright (c) 2019, Chris Fraire <[email protected]>.
2223
*/
2324
package org.opengrok.indexer.util;
2425

@@ -389,11 +390,16 @@ public static OptionParser scan(Consumer<OptionParser> parser) {
389390
public Option on(Object... args) {
390391

391392
Option opt = new Option();
392-
393+
394+
// Once description starts, then no other option settings are eligible.
395+
boolean addedDescription = false;
396+
393397
for (Object arg : args) {
394398
if (arg instanceof String) {
395399
String argument = (String) arg;
396-
if (argument.startsWith("--")) {
400+
if (addedDescription) {
401+
opt.addDescription(argument);
402+
} else if (argument.startsWith("--")) {
397403
// handle --switch --switch=ARG --switch=[OPT] --switch PLACE
398404
String[] parts = argument.split("[ =]");
399405

@@ -416,6 +422,7 @@ public Option on(Object... args) {
416422
} else {
417423
// this is description
418424
opt.addDescription(argument);
425+
addedDescription = true;
419426
}
420427
// This is indicator for a addOption of specific allowable option values
421428
} else if (arg instanceof String[]) {

0 commit comments

Comments
 (0)