UnifiedGenotyper now works without -varout or -vf set.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2464 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
b125571a98
commit
e32174fbc4
|
|
@ -58,6 +58,26 @@ public class GenotypeWriterArgumentTypeDescriptor extends ArgumentTypeDescriptor
|
|||
createGenotypeFormatArgumentDefinition(source) );
|
||||
}
|
||||
|
||||
/**
|
||||
* This command-line argument descriptor does want to override the provided default value.
|
||||
* @return true always.
|
||||
*/
|
||||
@Override
|
||||
public boolean overridesDefault() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the default value for this argument.
|
||||
* @return A VCFGenotypeWriter which writes to the default output stream.
|
||||
*/
|
||||
@Override
|
||||
public Object getDefault() {
|
||||
GenotypeWriterStub defaultGenotypeWriter = new VCFGenotypeWriterStub(engine,System.out);
|
||||
engine.addOutput(defaultGenotypeWriter);
|
||||
return defaultGenotypeWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given argument matches into a single object suitable for feeding into the ArgumentSource.
|
||||
* @param source Source for this argument.
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@ public class ArgumentSource {
|
|||
*/
|
||||
public final Field field;
|
||||
|
||||
/**
|
||||
* Type descriptor to use when parsing new argument types.
|
||||
*/
|
||||
private final ArgumentTypeDescriptor typeDescriptor;
|
||||
|
||||
/**
|
||||
* Create a new command-line argument target.
|
||||
* @param clazz Class containing the argument.
|
||||
|
|
@ -56,6 +61,7 @@ public class ArgumentSource {
|
|||
public ArgumentSource( Class clazz, Field field ) {
|
||||
this.clazz = clazz;
|
||||
this.field = field;
|
||||
this.typeDescriptor = ArgumentTypeDescriptor.create( field.getType() );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -89,10 +95,25 @@ public class ArgumentSource {
|
|||
* @return A non-null, non-empty list of argument definitions.
|
||||
*/
|
||||
public List<ArgumentDefinition> createArgumentDefinitions() {
|
||||
ArgumentTypeDescriptor typeDescriptor = ArgumentTypeDescriptor.create( field.getType() );
|
||||
return typeDescriptor.createArgumentDefinitions( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* This argument type descriptor wants to override any default value the user might have specified.
|
||||
* @return True if this descriptor wants to override any default the user specified. False otherwise.
|
||||
*/
|
||||
public boolean overridesDefault() {
|
||||
return typeDescriptor.overridesDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the default value for the command-line argument.
|
||||
* @return Default value to load into the object.
|
||||
*/
|
||||
public Object getDefault() {
|
||||
return typeDescriptor.getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the specified value based on the specified type.
|
||||
* @param source The type of value to be parsed.
|
||||
|
|
@ -101,10 +122,8 @@ public class ArgumentSource {
|
|||
*/
|
||||
public Object parse( ArgumentSource source, ArgumentMatches values ) {
|
||||
Object value = null;
|
||||
if( !isFlag() ) {
|
||||
ArgumentTypeDescriptor typeDescriptor = ArgumentTypeDescriptor.create( field.getType() );
|
||||
if( !isFlag() )
|
||||
value = typeDescriptor.parse( source, values );
|
||||
}
|
||||
else
|
||||
value = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,11 @@ public abstract class ArgumentTypeDescriptor {
|
|||
descriptors = allDescriptors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the given descriptor from the descriptor repository.
|
||||
* @param type Class for which to specify a descriptor.
|
||||
* @return descriptor for the given type.
|
||||
*/
|
||||
public static ArgumentTypeDescriptor create( Class type ) {
|
||||
for( ArgumentTypeDescriptor descriptor: descriptors ) {
|
||||
if( descriptor.supports(type) )
|
||||
|
|
@ -80,6 +85,22 @@ public abstract class ArgumentTypeDescriptor {
|
|||
*/
|
||||
public abstract boolean supports( Class type );
|
||||
|
||||
/**
|
||||
* This argument type descriptor wants to override any default value the user might have specified.
|
||||
* @return True if this descriptor wants to override any default the user specified. False otherwise.
|
||||
*/
|
||||
public boolean overridesDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the default value for the command-line argument.
|
||||
* @return Default value to load into the object.
|
||||
*/
|
||||
public Object getDefault() {
|
||||
throw new UnsupportedOperationException(String.format("Type descriptor %s cannot override default value of command-line argument",this.getClass()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the given argument source and attributes, synthesize argument definitions for command-line arguments.
|
||||
* @param source Source class and field for the given argument.
|
||||
|
|
@ -115,6 +136,7 @@ public abstract class ArgumentTypeDescriptor {
|
|||
/**
|
||||
* Retrieves the full name of the argument, specifiable with the '--' prefix. The full name can be
|
||||
* either specified explicitly with the fullName annotation parameter or implied by the field name.
|
||||
* @param source Original field specifying command-line arguments.
|
||||
* @return full name of the argument. Never null.
|
||||
*/
|
||||
protected String getFullName( ArgumentSource source ) {
|
||||
|
|
@ -125,6 +147,7 @@ public abstract class ArgumentTypeDescriptor {
|
|||
/**
|
||||
* Retrieves the short name of the argument, specifiable with the '-' prefix. The short name can
|
||||
* be specified or not; if left unspecified, no short name will be present.
|
||||
* @param source Original field specifying command-line arguments.
|
||||
* @return short name of the argument. Null if no short name exists.
|
||||
*/
|
||||
protected String getShortName( ArgumentSource source ) {
|
||||
|
|
@ -134,6 +157,7 @@ public abstract class ArgumentTypeDescriptor {
|
|||
|
||||
/**
|
||||
* Documentation for this argument. Mandatory field.
|
||||
* @param source Original field specifying command-line arguments.
|
||||
* @return Documentation for this argument.
|
||||
*/
|
||||
protected String getDoc( ArgumentSource source ) {
|
||||
|
|
@ -143,6 +167,7 @@ public abstract class ArgumentTypeDescriptor {
|
|||
|
||||
/**
|
||||
* Returns whether this field is required. Note that flag fields are always forced to 'not required'.
|
||||
* @param source Original field specifying command-line arguments.
|
||||
* @return True if the field is mandatory and not a boolean flag. False otherwise.
|
||||
*/
|
||||
protected boolean isRequired( ArgumentSource source ) {
|
||||
|
|
@ -152,6 +177,7 @@ public abstract class ArgumentTypeDescriptor {
|
|||
|
||||
/**
|
||||
* Specifies other arguments which cannot be used in conjunction with tihs argument. Comma-separated list.
|
||||
* @param source Original field specifying command-line arguments.
|
||||
* @return A comma-separated list of exclusive arguments, or null if none are present.
|
||||
*/
|
||||
protected String getExclusiveOf( ArgumentSource source ) {
|
||||
|
|
@ -161,6 +187,7 @@ public abstract class ArgumentTypeDescriptor {
|
|||
|
||||
/**
|
||||
* A regular expression which can be used for validation.
|
||||
* @param source Original field specifying command-line arguments.
|
||||
* @return a JVM regex-compatible regular expression, or null to permit any possible value.
|
||||
*/
|
||||
protected String getValidationRegex( ArgumentSource source ) {
|
||||
|
|
|
|||
|
|
@ -250,7 +250,7 @@ public class ParsingEngine {
|
|||
public void loadArgumentsIntoObject( Object object ) {
|
||||
List<ArgumentSource> argumentSources = extractArgumentSources(object.getClass());
|
||||
for( ArgumentSource argumentSource: argumentSources )
|
||||
loadMatchesIntoObject( argumentSource, object, argumentMatches.findMatches(argumentSource) );
|
||||
loadValueIntoObject( argumentSource, object, argumentMatches.findMatches(argumentSource) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -259,9 +259,9 @@ public class ParsingEngine {
|
|||
* @param source Argument source to load into the object.
|
||||
* @param instance Object into which to inject the value. The target might be in a container within the instance.
|
||||
*/
|
||||
private void loadMatchesIntoObject( ArgumentSource source, Object instance, ArgumentMatches argumentMatches ) {
|
||||
private void loadValueIntoObject( ArgumentSource source, Object instance, ArgumentMatches argumentMatches ) {
|
||||
// Nothing to load
|
||||
if( argumentMatches.size() == 0 )
|
||||
if( argumentMatches.size() == 0 && !source.overridesDefault())
|
||||
return;
|
||||
|
||||
// Target instance into which to inject the value.
|
||||
|
|
@ -280,8 +280,8 @@ public class ParsingEngine {
|
|||
throw new StingException("Internal command-line parser error: unable to find a home for argument matches " + argumentMatches);
|
||||
|
||||
for( Object target: targets ) {
|
||||
Object value = source.parse( source, argumentMatches );
|
||||
JVMUtils.setFieldValue( source.field, target, value );
|
||||
Object value = (argumentMatches.size() != 0) ? source.parse(source,argumentMatches) : source.getDefault();
|
||||
JVMUtils.setFieldValue(source.field,target,value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue