Class CliTools


  • public class CliTools
    extends Object
    Utilities for autoconfiguring javabeans based on command line arguments.
    Author:
    Thomas Down
    • Method Detail

      • configureBean

        public static String[] configureBean​(Object bean,
                                             String[] args)
                                      throws ConfigurationException
        Configure a JavaBean based on a set of command line arguments. For a command line construct such as "-foo 42", this method will use available BeanInfo (usually obtained by introspection) to find a property named "foo". The argument will be interpreted according to the type of the "foo" property, then the appropriate mutator method (generally named setFoo) will be called to configure the property on the bean.

        Currently supported property types are int, double, boolean, String, File, Reader, Writer, InputStream, OutputStream, Enum, plus arrays of all the above types. In the case of arrays, the option may appear multiple times on the command line, otherwise recurrance of the same option is an error.

        For stream types, the parameter is interpreted as a filename unless it is equal to "-" in which case standard input or standard output are used as appropriate. Each of the standard streams may only be used one.

        In the future, this method will probably be extended to handle multiple parameter occurances, and use Annotations to generate more useful help messages when something goes wrong.

        Parameters:
        bean -
        args -
        Returns:
        A string array which contains any 'anonymous' arguments (may be empty)
        Throws:
        ConfigurationException
      • getEnumValuesAsString

        public static <T extends Enum<?>> String getEnumValuesAsString​(Class<T> enumClass)
        Constructs a comma-separated list of values for an enum. Example: > getEnumValues(ScoringStrategy.class) "CA_SCORING, SIDE_CHAIN_SCORING, SIDE_CHAIN_ANGLE_SCORING, CA_AND_SIDE_CHAIN_ANGLE_SCORING, or SEQUENCE_CONSERVATION"
        Parameters:
        enumClass -
        Returns: