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

View File

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

View File

@ -51,6 +51,16 @@ public class ArgumentDefinition {
*/
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?
*/
@ -61,28 +71,31 @@ public class ArgumentDefinition {
*/
public final String validation;
/**
* The target into which to inject arguments meeting this definition.
*/
public final ArgumentSource source;
/**
* 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,
String fullName,
public ArgumentDefinition( String fullName,
String shortName,
String doc,
boolean required,
boolean isFlag,
boolean isMultiValued,
String exclusiveOf,
String validation ) {
this.source = source;
this.fullName = fullName;
this.shortName = shortName;
this.doc = doc;
this.required = required;
this.isFlag = isFlag;
this.isMultiValued = isMultiValued;
this.exclusiveOf = exclusiveOf;
this.validation = validation;
}
@ -110,6 +123,8 @@ public class ArgumentDefinition {
Utils.equals(shortName,other.shortName) &&
Utils.equals(doc,other.doc) &&
required == other.required &&
isFlag == other.isFlag &&
isMultiValued == other.isMultiValued &&
Utils.equals(exclusiveOf,other.exclusiveOf) &&
Utils.equals(validation,other.validation);
}

View File

@ -100,9 +100,11 @@ public class ArgumentMatches implements Iterable<ArgumentMatch> {
*/
ArgumentMatches findMatches( ArgumentSource argumentSource ) {
List<ArgumentDefinition> sourceDefinitions = ArgumentTypeDescriptor.create(argumentSource.field.getType()).createArgumentDefinitions(argumentSource);
ArgumentMatches matches = new ArgumentMatches();
for( ArgumentMatch argumentMatch: getUniqueMatches() ) {
if( argumentMatch.definition != null && argumentMatch.definition.source.equals( argumentSource ) )
if( sourceDefinitions.contains(argumentMatch.definition) )
matches.mergeInto( argumentMatch );
}
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.
*/
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.
*/
protected ArgumentDefinition createDefaultArgumentDefinition( ArgumentSource source ) {
return new ArgumentDefinition( source,
getFullName(source),
return new ArgumentDefinition( getFullName(source),
getShortName(source),
getDoc(source),
isRequired(source),
source.isFlag(),
source.isMultiValued(),
getExclusiveOf(source),
getValidationRegex(source) );
}

View File

@ -214,7 +214,7 @@ public class ParsingEngine {
Collection<ArgumentMatch> overvaluedArguments = new ArrayList<ArgumentMatch>();
for( ArgumentMatch argumentMatch: argumentMatches.findSuccessfulMatches() ) {
// 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);
}

View File

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