Cleanup.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@205 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
728f932ecf
commit
f7097c8ee7
|
|
@ -356,7 +356,7 @@ public class ArgumentParser {
|
||||||
* will be alone a set. Every option should appear in exactly one set.
|
* will be alone a set. Every option should appear in exactly one set.
|
||||||
* WARNING: Has no concept of nested dependencies.
|
* WARNING: Has no concept of nested dependencies.
|
||||||
* @param fields list of fields for which to check options.
|
* @param fields list of fields for which to check options.
|
||||||
* @return
|
* @return groupings of mutually exclusive options.
|
||||||
*/
|
*/
|
||||||
private List<Set<Field>> groupExclusiveOptions( Field[] fields ) {
|
private List<Set<Field>> groupExclusiveOptions( Field[] fields ) {
|
||||||
List<Set<Field>> optionGroups = new ArrayList<Set<Field>>();
|
List<Set<Field>> optionGroups = new ArrayList<Set<Field>>();
|
||||||
|
|
@ -414,30 +414,42 @@ public class ArgumentParser {
|
||||||
String shortName = (argument.shortName().length() != 0) ? argument.shortName() : fullName.substring(0,1);
|
String shortName = (argument.shortName().length() != 0) ? argument.shortName() : fullName.substring(0,1);
|
||||||
if(shortName.length() != 1)
|
if(shortName.length() != 1)
|
||||||
throw new IllegalArgumentException("Invalid short name: " + shortName);
|
throw new IllegalArgumentException("Invalid short name: " + shortName);
|
||||||
|
String description = argument.doc();
|
||||||
|
boolean isRequired = argument.required();
|
||||||
boolean isFlag = (field.getType() == Boolean.class) || (field.getType() == Boolean.TYPE);
|
boolean isFlag = (field.getType() == Boolean.class) || (field.getType() == Boolean.TYPE);
|
||||||
boolean isCollection = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
|
boolean isCollection = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
|
||||||
|
|
||||||
if( isFlag && isCollection )
|
if( isFlag && isCollection )
|
||||||
throw new IllegalArgumentException("Can't have an array of flags.");
|
throw new IllegalArgumentException("Can't have an array of flags.");
|
||||||
|
|
||||||
String description = String.format("[%s] %s", sourceName, argument.doc());
|
OptionBuilder.withLongOpt(fullName);
|
||||||
|
|
||||||
OptionBuilder ob = OptionBuilder.withLongOpt(fullName);
|
|
||||||
if( !isFlag ) {
|
if( !isFlag ) {
|
||||||
ob = ob.withArgName(fullName);
|
OptionBuilder.withArgName(fullName);
|
||||||
ob = isCollection ? ob.hasArgs() : ob.hasArg();
|
if( isCollection )
|
||||||
|
OptionBuilder.hasArgs();
|
||||||
|
else
|
||||||
|
OptionBuilder.hasArg();
|
||||||
}
|
}
|
||||||
if( argument.required() ) {
|
if( isRequired ) {
|
||||||
ob = ob.isRequired();
|
OptionBuilder.isRequired();
|
||||||
description = String.format("[%s] (Required Option) %s", sourceName, argument.doc());
|
description = String.format("(Required Option) %s", description);
|
||||||
}
|
|
||||||
if( description.length() != 0 ) ob = ob.withDescription( description );
|
|
||||||
|
|
||||||
Option option = ob.create( shortName );
|
|
||||||
|
|
||||||
return option;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceName = sourceName.trim();
|
||||||
|
if( sourceName.length() > 0 )
|
||||||
|
description = String.format("[%s] %s", sourceName, description );
|
||||||
|
|
||||||
|
if( description.length() != 0 ) OptionBuilder.withDescription( description );
|
||||||
|
|
||||||
|
return OptionBuilder.create( shortName );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a command-line argument given a string and field.
|
||||||
|
* @param f Field type from which to infer the type.
|
||||||
|
* @param strs Collection of parameter strings to parse.
|
||||||
|
* @return Parsed object of the inferred type.
|
||||||
|
*/
|
||||||
private Object constructFromString(Field f, String[] strs) {
|
private Object constructFromString(Field f, String[] strs) {
|
||||||
Class type = f.getType();
|
Class type = f.getType();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue