Skip to content

Commit c2e9117

Browse files
authored
Filter non-CLPs from inclusion in tab completion. (#164)
1 parent 444c4cd commit c2e9117

File tree

5 files changed

+73
-42
lines changed

5 files changed

+73
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.broadinstitute.barclay.help;
2+
3+
/**
4+
* Work unit handler for tab completion work units.
5+
*/
6+
public class BashTabCompletionDocWorkUnitHandler extends DefaultDocWorkUnitHandler {
7+
8+
/**
9+
* @param doclet for this run. May not be null.
10+
*/
11+
public BashTabCompletionDocWorkUnitHandler(final HelpDoclet doclet) {
12+
super(doclet);
13+
}
14+
15+
/**
16+
* Add bindings describing related capabilities to currentWorkUnit. The tab completion doclet filters
17+
* out any work unit that represents a class that doesn't have
18+
* {@link org.broadinstitute.barclay.argparser.CommandLineProgramProperties}. Since doing so may filter
19+
* out classes that are referenced by the extraDocs attribute in classes that ARE
20+
* {@link org.broadinstitute.barclay.argparser.CommandLineProgramProperties}, we need to suppress
21+
* resolution of extraDocs for tab completion work units by overriding this method to do nothing.
22+
*/
23+
@Override
24+
protected void addExtraDocsBindings(final DocWorkUnit currentWorkUnit) { }
25+
26+
}

Diff for: src/main/java/org/broadinstitute/barclay/help/BashTabCompletionDoclet.java

+33
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package org.broadinstitute.barclay.help;
22

3+
import com.sun.javadoc.ClassDoc;
34
import com.sun.javadoc.RootDoc;
45
import freemarker.template.Configuration;
56
import freemarker.template.Template;
67
import freemarker.template.TemplateException;
8+
import org.broadinstitute.barclay.argparser.CommandLineProgramProperties;
79

810
import java.io.*;
911
import java.util.*;
@@ -390,6 +392,37 @@ else if (option[0].equals(CALLER_SCRIPT_POSTFIX_ARG_MAX_OCCURRENCES)) {
390392
return hasParsedOption;
391393
}
392394

395+
/**
396+
* Filter out features that are not command line programs by selecting only classes with
397+
* {@link CommandLineProgramProperties}.
398+
* @param documentedFeature feature that is being considered for inclusion in the docs
399+
* @param classDoc for the class that is being considered for inclusion in the docs
400+
* @param clazz class that is being considered for inclusion in the docs
401+
* @return
402+
*/
403+
@Override
404+
public boolean includeInDocs(final DocumentedFeature documentedFeature, final ClassDoc classDoc, final Class<?> clazz) {
405+
return super.includeInDocs(documentedFeature, classDoc, clazz) &&
406+
clazz.getAnnotation(CommandLineProgramProperties.class) != null;
407+
}
408+
409+
/**
410+
* Create a work unit and handler capable of handling the feature specified by the input arguments.
411+
* Returns null if no appropriate handler is found or doc shouldn't be documented at all.
412+
*/
413+
@Override
414+
protected DocWorkUnit createWorkUnit(
415+
final DocumentedFeature documentedFeature,
416+
final ClassDoc classDoc,
417+
final Class<?> clazz)
418+
{
419+
return new DocWorkUnit(
420+
new BashTabCompletionDocWorkUnitHandler(this),
421+
documentedFeature,
422+
classDoc,
423+
clazz);
424+
}
425+
393426
@Override
394427
protected void processWorkUnitTemplate(
395428
final Configuration cfg,

Diff for: src/main/java/org/broadinstitute/barclay/help/HelpDoclet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ private Set<DocWorkUnit> computeWorkUnits() {
296296
final DocumentedFeature documentedFeature = getDocumentedFeatureForClass(clazz);
297297

298298
if (documentedFeature != null) {
299-
if (documentedFeature.enable()) {
300-
DocWorkUnit workUnit = createWorkUnit(
299+
if (documentedFeature.enable() && includeInDocs(documentedFeature, classDoc, clazz)) {
300+
DocWorkUnit workUnit = createWorkUnit(
301301
documentedFeature,
302302
classDoc,
303303
clazz);

Diff for: src/test/resources/org/broadinstitute/barclay/help/expected/BashTabCompletionDoclet/bashTabCompletionDocletTestLaunch-completion.sh

+6-20
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
CALLER_SCRIPT_NAME="bashTabCompletionDocletTestLaunch"
1212

1313
# A description of these variables is below in the main completion function (_masterCompletionFunction)
14-
CS_PREFIX_OPTIONS_ALL_LEGAL_ARGUMENTS=(--pre-help --pre-info --pre-inputFile TestExtraDocs TestArgumentContainer )
15-
CS_PREFIX_OPTIONS_NORMAL_COMPLETION_ARGUMENTS=(--pre-help --pre-info --pre-inputFile TestExtraDocs TestArgumentContainer )
16-
CS_PREFIX_OPTIONS_ALL_ARGUMENT_VALUE_TYPES=("null" "null" "File" "null" "null" )
14+
CS_PREFIX_OPTIONS_ALL_LEGAL_ARGUMENTS=(--pre-help --pre-info --pre-inputFile TestArgumentContainer )
15+
CS_PREFIX_OPTIONS_NORMAL_COMPLETION_ARGUMENTS=(--pre-help --pre-info --pre-inputFile TestArgumentContainer )
16+
CS_PREFIX_OPTIONS_ALL_ARGUMENT_VALUE_TYPES=("null" "null" "File" "null" )
1717
CS_PREFIX_OPTIONS_MUTUALLY_EXCLUSIVE_ARGS=("--pre-help;pre-info,pre-inputFile" "--pre-info;pre-help,pre-inputFile")
1818
CS_PREFIX_OPTIONS_SYNONYMOUS_ARGS=("--pre-help;-prh" "--pre-inputFile;-prif")
19-
CS_PREFIX_OPTIONS_MIN_OCCURRENCES=(0 0 1 0 0 )
20-
CS_PREFIX_OPTIONS_MAX_OCCURRENCES=(1 1 1 1 1 )
19+
CS_PREFIX_OPTIONS_MIN_OCCURRENCES=(0 0 1 0 )
20+
CS_PREFIX_OPTIONS_MAX_OCCURRENCES=(1 1 1 1 )
2121

2222
CS_POSTFIX_OPTIONS_ALL_LEGAL_ARGUMENTS=(--post-help --post-info --post-inputFile)
2323
CS_POSTFIX_OPTIONS_NORMAL_COMPLETION_ARGUMENTS=(--post-help --post-info --post-inputFile)
@@ -31,7 +31,7 @@ CS_POSTFIX_OPTIONS_MAX_OCCURRENCES=(1 1 1)
3131
HAS_POSTFIX_OPTIONS="true"
3232

3333
# All the tool names we are able to complete:
34-
ALL_TOOLS=(TestExtraDocs TestArgumentContainer )
34+
ALL_TOOLS=(TestArgumentContainer )
3535

3636
####################################################################################################
3737

@@ -422,20 +422,6 @@ _bashTabCompletionDocletTestLaunch_masterCompletionFunction()
422422
# Set our reply as a list of the possible tool matches:
423423
COMPREPLY=( $(compgen -W '${possibleToolMatches[@]}' -- $cur) )
424424

425-
elif [[ ${toolName} == "TestExtraDocs" ]] ; then
426-
427-
# Set up the completion information for this tool:
428-
DEPENDENT_ARGUMENTS=()
429-
NORMAL_COMPLETION_ARGUMENTS=(--extraDocsArgument )
430-
MUTUALLY_EXCLUSIVE_ARGS=()
431-
SYNONYMOUS_ARGS=("--extraDocsArgument;-extDocArg" )
432-
MIN_OCCURRENCES=(0 )
433-
MAX_OCCURRENCES=(2147483647 )
434-
ALL_LEGAL_ARGUMENTS=(--extraDocsArgument )
435-
ALL_ARGUMENT_VALUE_TYPES=("String" )
436-
437-
# Complete the arguments for this tool:
438-
_bashTabCompletionDocletTestLaunch_handleArgs
439425
elif [[ ${toolName} == "TestArgumentContainer" ]] ; then
440426

441427
# Set up the completion information for this tool:

Diff for: src/test/resources/org/broadinstitute/barclay/help/expected/BashTabCompletionDoclet/bashTabCompletionDocletTestLaunchWithDefaults-completion.sh

+6-20
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
CALLER_SCRIPT_NAME="bashTabCompletionDocletTestLaunchWithDefaults"
1212

1313
# A description of these variables is below in the main completion function (_masterCompletionFunction)
14-
CS_PREFIX_OPTIONS_ALL_LEGAL_ARGUMENTS=( TestExtraDocs TestArgumentContainer )
15-
CS_PREFIX_OPTIONS_NORMAL_COMPLETION_ARGUMENTS=( TestExtraDocs TestArgumentContainer )
16-
CS_PREFIX_OPTIONS_ALL_ARGUMENT_VALUE_TYPES=( "null" "null" )
14+
CS_PREFIX_OPTIONS_ALL_LEGAL_ARGUMENTS=( TestArgumentContainer )
15+
CS_PREFIX_OPTIONS_NORMAL_COMPLETION_ARGUMENTS=( TestArgumentContainer )
16+
CS_PREFIX_OPTIONS_ALL_ARGUMENT_VALUE_TYPES=( "null" )
1717
CS_PREFIX_OPTIONS_MUTUALLY_EXCLUSIVE_ARGS=()
1818
CS_PREFIX_OPTIONS_SYNONYMOUS_ARGS=()
19-
CS_PREFIX_OPTIONS_MIN_OCCURRENCES=( 0 0 )
20-
CS_PREFIX_OPTIONS_MAX_OCCURRENCES=( 1 1 )
19+
CS_PREFIX_OPTIONS_MIN_OCCURRENCES=( 0 )
20+
CS_PREFIX_OPTIONS_MAX_OCCURRENCES=( 1 )
2121

2222
CS_POSTFIX_OPTIONS_ALL_LEGAL_ARGUMENTS=()
2323
CS_POSTFIX_OPTIONS_NORMAL_COMPLETION_ARGUMENTS=()
@@ -31,7 +31,7 @@ CS_POSTFIX_OPTIONS_MAX_OCCURRENCES=()
3131
HAS_POSTFIX_OPTIONS="false"
3232

3333
# All the tool names we are able to complete:
34-
ALL_TOOLS=(TestExtraDocs TestArgumentContainer )
34+
ALL_TOOLS=(TestArgumentContainer )
3535

3636
####################################################################################################
3737

@@ -422,20 +422,6 @@ _bashTabCompletionDocletTestLaunchWithDefaults_masterCompletionFunction()
422422
# Set our reply as a list of the possible tool matches:
423423
COMPREPLY=( $(compgen -W '${possibleToolMatches[@]}' -- $cur) )
424424

425-
elif [[ ${toolName} == "TestExtraDocs" ]] ; then
426-
427-
# Set up the completion information for this tool:
428-
DEPENDENT_ARGUMENTS=()
429-
NORMAL_COMPLETION_ARGUMENTS=(--extraDocsArgument )
430-
MUTUALLY_EXCLUSIVE_ARGS=()
431-
SYNONYMOUS_ARGS=("--extraDocsArgument;-extDocArg" )
432-
MIN_OCCURRENCES=(0 )
433-
MAX_OCCURRENCES=(2147483647 )
434-
ALL_LEGAL_ARGUMENTS=(--extraDocsArgument )
435-
ALL_ARGUMENT_VALUE_TYPES=("String" )
436-
437-
# Complete the arguments for this tool:
438-
_bashTabCompletionDocletTestLaunchWithDefaults_handleArgs
439425
elif [[ ${toolName} == "TestArgumentContainer" ]] ; then
440426

441427
# Set up the completion information for this tool:

0 commit comments

Comments
 (0)