From f7097c8ee71f79d91a81ab529e3e5f147952efcd Mon Sep 17 00:00:00 2001 From: hanna Date: Thu, 26 Mar 2009 21:24:12 +0000 Subject: [PATCH] Cleanup. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@205 348d0f76-0448-11de-a6fe-93d51630548a --- .../sting/utils/cmdLine/ArgumentParser.java | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentParser.java b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentParser.java index eabe3f3b5..37cc4f749 100644 --- a/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentParser.java +++ b/java/src/org/broadinstitute/sting/utils/cmdLine/ArgumentParser.java @@ -356,7 +356,7 @@ public class ArgumentParser { * will be alone a set. Every option should appear in exactly one set. * WARNING: Has no concept of nested dependencies. * @param fields list of fields for which to check options. - * @return + * @return groupings of mutually exclusive options. */ private List> groupExclusiveOptions( Field[] fields ) { List> optionGroups = new ArrayList>(); @@ -414,30 +414,42 @@ public class ArgumentParser { String shortName = (argument.shortName().length() != 0) ? argument.shortName() : fullName.substring(0,1); if(shortName.length() != 1) 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 isCollection = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()); if( isFlag && isCollection ) throw new IllegalArgumentException("Can't have an array of flags."); - String description = String.format("[%s] %s", sourceName, argument.doc()); - - OptionBuilder ob = OptionBuilder.withLongOpt(fullName); + OptionBuilder.withLongOpt(fullName); if( !isFlag ) { - ob = ob.withArgName(fullName); - ob = isCollection ? ob.hasArgs() : ob.hasArg(); + OptionBuilder.withArgName(fullName); + if( isCollection ) + OptionBuilder.hasArgs(); + else + OptionBuilder.hasArg(); } - if( argument.required() ) { - ob = ob.isRequired(); - description = String.format("[%s] (Required Option) %s", sourceName, argument.doc()); + if( isRequired ) { + OptionBuilder.isRequired(); + description = String.format("(Required Option) %s", description); } - if( description.length() != 0 ) ob = ob.withDescription( description ); - Option option = ob.create( shortName ); + sourceName = sourceName.trim(); + if( sourceName.length() > 0 ) + description = String.format("[%s] %s", sourceName, description ); - return option; + 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) { Class type = f.getType();