Get rid of backlink from ArgumentDefinitions to ArgumentSources. This will help in the future with multiple

source -> single definition mapping sets.


git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2417 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2009-12-21 00:39:36 +00:00
parent 9e53c06328
commit 11cbfcec9c
7 changed files with 47 additions and 25 deletions

View File

@ -112,11 +112,12 @@ public class GenotypeWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
else else
shortName = null; shortName = null;
return new ArgumentDefinition( source, return new ArgumentDefinition( fullName,
fullName,
shortName, shortName,
getDoc(source), getDoc(source),
isRequired(source), isRequired(source),
false,
source.isMultiValued(),
getExclusiveOf(source), getExclusiveOf(source),
getValidationRegex(source) ); getValidationRegex(source) );
} }
@ -127,11 +128,12 @@ public class GenotypeWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
* @return Argument definition for the BAM file itself. Will not be null. * @return Argument definition for the BAM file itself. Will not be null.
*/ */
private ArgumentDefinition createGenotypeFormatArgumentDefinition(ArgumentSource source) { private ArgumentDefinition createGenotypeFormatArgumentDefinition(ArgumentSource source) {
return new ArgumentDefinition( source, return new ArgumentDefinition( "variant_output_format",
"variant_output_format",
"vf", "vf",
"Format to be used to represent variants; default is VCF", "Format to be used to represent variants; default is VCF",
false, false,
false,
false,
null, null,
null ); null );
} }

View File

@ -110,11 +110,12 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
else else
shortName = null; shortName = null;
return new ArgumentDefinition( source, return new ArgumentDefinition( fullName,
fullName,
shortName, shortName,
getDoc(source), getDoc(source),
isRequired(source), isRequired(source),
false,
source.isMultiValued(),
getExclusiveOf(source), getExclusiveOf(source),
getValidationRegex(source) ); getValidationRegex(source) );
} }
@ -125,11 +126,12 @@ public class SAMFileWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
* @return Argument definition for the BAM file itself. Will not be null. * @return Argument definition for the BAM file itself. Will not be null.
*/ */
private ArgumentDefinition createBAMCompressionArgumentDefinition(ArgumentSource source) { private ArgumentDefinition createBAMCompressionArgumentDefinition(ArgumentSource source) {
return new ArgumentDefinition( source, return new ArgumentDefinition( COMPRESSION_FULLNAME,
COMPRESSION_FULLNAME,
COMPRESSION_SHORTNAME, COMPRESSION_SHORTNAME,
"Compression level to use for writing BAM files", "Compression level to use for writing BAM files",
false, false,
false,
false,
null, null,
null ); null );
} }

View File

@ -51,6 +51,16 @@ public class ArgumentDefinition {
*/ */
public final boolean required; public final boolean required;
/**
* Is this argument a flag? Users can't specify a value for a flag.
*/
public final boolean isFlag;
/**
* Does this argument support multiple values (repeated "-arg value1 -arg value2"-style structures).
*/
public final boolean isMultiValued;
/** /**
* Is this argument exclusive of other arguments? * Is this argument exclusive of other arguments?
*/ */
@ -61,28 +71,31 @@ public class ArgumentDefinition {
*/ */
public final String validation; public final String validation;
/**
* The target into which to inject arguments meeting this definition.
*/
public final ArgumentSource source;
/** /**
* Creates a new argument definition. * Creates a new argument definition.
* @param source Source information for defining the argument. * @param fullName Full name for this argument definition.
* @param shortName Short name for this argument definition.
* @param doc Doc string for this argument.
* @param required Whether or not this argument is required.
* @param isFlag Whether or not this argument should be treated as a flag.
* @param isMultiValued Whether or not this argument supports multiple values.
* @param exclusiveOf Whether this command line argument is mutually exclusive of other arguments.
* @param validation A regular expression for command-line argument validation.
*/ */
public ArgumentDefinition( ArgumentSource source, public ArgumentDefinition( String fullName,
String fullName,
String shortName, String shortName,
String doc, String doc,
boolean required, boolean required,
boolean isFlag,
boolean isMultiValued,
String exclusiveOf, String exclusiveOf,
String validation ) { String validation ) {
this.source = source;
this.fullName = fullName; this.fullName = fullName;
this.shortName = shortName; this.shortName = shortName;
this.doc = doc; this.doc = doc;
this.required = required; this.required = required;
this.isFlag = isFlag;
this.isMultiValued = isMultiValued;
this.exclusiveOf = exclusiveOf; this.exclusiveOf = exclusiveOf;
this.validation = validation; this.validation = validation;
} }
@ -110,6 +123,8 @@ public class ArgumentDefinition {
Utils.equals(shortName,other.shortName) && Utils.equals(shortName,other.shortName) &&
Utils.equals(doc,other.doc) && Utils.equals(doc,other.doc) &&
required == other.required && required == other.required &&
isFlag == other.isFlag &&
isMultiValued == other.isMultiValued &&
Utils.equals(exclusiveOf,other.exclusiveOf) && Utils.equals(exclusiveOf,other.exclusiveOf) &&
Utils.equals(validation,other.validation); Utils.equals(validation,other.validation);
} }

View File

@ -100,9 +100,11 @@ public class ArgumentMatches implements Iterable<ArgumentMatch> {
*/ */
ArgumentMatches findMatches( ArgumentSource argumentSource ) { ArgumentMatches findMatches( ArgumentSource argumentSource ) {
List<ArgumentDefinition> sourceDefinitions = ArgumentTypeDescriptor.create(argumentSource.field.getType()).createArgumentDefinitions(argumentSource);
ArgumentMatches matches = new ArgumentMatches(); ArgumentMatches matches = new ArgumentMatches();
for( ArgumentMatch argumentMatch: getUniqueMatches() ) { for( ArgumentMatch argumentMatch: getUniqueMatches() ) {
if( argumentMatch.definition != null && argumentMatch.definition.source.equals( argumentSource ) ) if( sourceDefinitions.contains(argumentMatch.definition) )
matches.mergeInto( argumentMatch ); matches.mergeInto( argumentMatch );
} }
return matches; return matches;
@ -374,6 +376,6 @@ class ArgumentMatch implements Iterable<ArgumentMatch> {
* @return True if definition is known to be a flag; false if not known to be a flag. * @return True if definition is known to be a flag; false if not known to be a flag.
*/ */
private boolean isArgumentFlag() { private boolean isArgumentFlag() {
return definition != null && definition.source.isFlag(); return definition != null && definition.isFlag;
} }
} }

View File

@ -100,11 +100,12 @@ public abstract class ArgumentTypeDescriptor {
* @return The default definition for this argument source. * @return The default definition for this argument source.
*/ */
protected ArgumentDefinition createDefaultArgumentDefinition( ArgumentSource source ) { protected ArgumentDefinition createDefaultArgumentDefinition( ArgumentSource source ) {
return new ArgumentDefinition( source, return new ArgumentDefinition( getFullName(source),
getFullName(source),
getShortName(source), getShortName(source),
getDoc(source), getDoc(source),
isRequired(source), isRequired(source),
source.isFlag(),
source.isMultiValued(),
getExclusiveOf(source), getExclusiveOf(source),
getValidationRegex(source) ); getValidationRegex(source) );
} }

View File

@ -214,7 +214,7 @@ public class ParsingEngine {
Collection<ArgumentMatch> overvaluedArguments = new ArrayList<ArgumentMatch>(); Collection<ArgumentMatch> overvaluedArguments = new ArrayList<ArgumentMatch>();
for( ArgumentMatch argumentMatch: argumentMatches.findSuccessfulMatches() ) { for( ArgumentMatch argumentMatch: argumentMatches.findSuccessfulMatches() ) {
// Warning: assumes that definition is not null (asserted by checks above). // Warning: assumes that definition is not null (asserted by checks above).
if( !argumentMatch.definition.source.isMultiValued() && argumentMatch.values().size() > 1 ) if( !argumentMatch.definition.isMultiValued && argumentMatch.values().size() > 1 )
overvaluedArguments.add(argumentMatch); overvaluedArguments.add(argumentMatch);
} }

View File

@ -75,7 +75,7 @@ public class HelpFormatter {
lineFormatter.format("-%s", argumentDefinition.shortName); lineFormatter.format("-%s", argumentDefinition.shortName);
else else
lineFormatter.format("--%s", argumentDefinition.fullName); lineFormatter.format("--%s", argumentDefinition.fullName);
if( !argumentDefinition.source.isFlag() ) if( !argumentDefinition.isFlag )
lineFormatter.format(" <%s>", argumentDefinition.fullName); lineFormatter.format(" <%s>", argumentDefinition.fullName);
if( !argumentDefinition.required ) lineFormatter.format("]"); if( !argumentDefinition.required ) lineFormatter.format("]");
} }
@ -157,7 +157,7 @@ public class HelpFormatter {
if( argumentDefinition.shortName != null ) if( argumentDefinition.shortName != null )
formatter.format("-%s,", argumentDefinition.shortName); formatter.format("-%s,", argumentDefinition.shortName);
formatter.format("--%s", argumentDefinition.fullName); formatter.format("--%s", argumentDefinition.fullName);
if( !argumentDefinition.source.isFlag() ) if( !argumentDefinition.isFlag )
formatter.format(" <%s>", argumentDefinition.fullName); formatter.format(" <%s>", argumentDefinition.fullName);
return builder.toString(); return builder.toString();