public class ArgumentParser
extends java.lang.Object
import edu.stanford.nlp.util.ArgumentParser.Option
class Props {
@Option(name="anIntOption", required=false, gloss="This is an int")
public static int anIntOption = 7; // default value is 7
@Option(name="anotherOption", required=false)
public static File aCastableOption = new File("/foo");
}
You can then set options with fillOptions(String...)
,
or with fillOptions(java.util.Properties)
.
If your default classpath has many classes in it, you can select a subset of them
by using fillOptions(Class[], java.util.Properties)
, or some variant.
A complete toy example looks like this:
import java.util.Properties;
import edu.stanford.nlp.util.ArgumentParser;
import edu.stanford.nlp.util.StringUtils;
public class Foo {
@ArgumentParser.Option(name="bar", gloss="This is a string option.", required=true)
private static String BAR = null;
public static void main(String[] args) {
// Parse the arguments
Properties props = StringUtils.argsToProperties(args);
ArgumentParser.fillOptions(new Class[]{ Foo.class, ArgumentParser.class }, props);
log.info(INPUT);
}
}
Modifier and Type | Class and Description |
---|---|
static interface |
ArgumentParser.Option |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
host |
static java.lang.Class<?>[] |
optionClasses |
static int |
threads |
Modifier and Type | Method and Description |
---|---|
static void |
fillOptions(java.lang.Class<?>[] classes,
java.util.Properties options)
Populate all static options in the given set of classes, as defined by the given
properties.
|
static void |
fillOptions(java.lang.Class<?>[] optionClasses,
java.util.Properties props,
java.lang.String... args)
Populate all static
ArgumentParser.Option -tagged fields in the given classes with the given Properties. |
static void |
fillOptions(java.lang.Class<?>[] classes,
java.lang.String... args)
Populate with the given command-line arguments all static
ArgumentParser.Option -tagged fields in
the given classes. |
static void |
fillOptions(java.lang.Class<?> clazz,
java.util.Properties options)
Populate all static options in the given class, as defined by the given
properties.
|
static void |
fillOptions(java.lang.Class<?> clazz,
java.util.Properties props,
java.lang.String... args)
Populate all static options in the given class, as defined by the given properties.
|
static void |
fillOptions(java.lang.Class<?> clazz,
java.lang.String... args)
Populate all static options in the given class, as defined by the given
command-line arguments.
|
static void |
fillOptions(java.lang.Object[] instances,
java.util.Properties options)
Fill all non-static
ArgumentParser.Option -tagged fields in the given set of objects with the given
properties. |
static void |
fillOptions(java.lang.Object[] instances,
java.lang.String[] args)
Fill all non-static
ArgumentParser.Option -tagged fields in the given set of objects with the given
command-line arguments. |
static void |
fillOptions(java.lang.Object instance,
java.util.Properties options)
Fill all non-static
ArgumentParser.Option -tagged fields in the given object with the given
properties. |
static void |
fillOptions(java.lang.Object instance,
java.util.Properties props,
java.lang.String... args)
Populate all static options in the given class, as defined by the given properties.
|
static void |
fillOptions(java.lang.Object instance,
java.lang.String... args)
Fill all non-static
ArgumentParser.Option -tagged fields in the given object with the given
command-line arguments. |
static void |
fillOptions(java.lang.Object subcomponent,
java.lang.String subcomponentName,
java.util.Properties props)
Fill all the options for a given subcomponent.
|
static void |
fillOptions(java.util.Properties props)
Populate with the given properties all static options in all classes in the current classpath.
|
static void |
fillOptions(java.util.Properties props,
java.lang.String... args)
Populate all static
ArgumentParser.Option -tagged fields in the given classes with the given Properties. |
static void |
fillOptions(java.lang.String... args)
Populate with the given command-line arguments all static options in all
classes in the current classpath.
|
static java.util.List<java.lang.String> |
listOptions(java.lang.Class c)
Return the list of
ArgumentParser.Option 's for provided Class |
static java.lang.String |
usage(java.lang.Class[] optionsClasses)
Return a string describing the usage of the program this method is called from, given the
options declared in the given set of classes.
|
static java.lang.String |
usage(java.lang.Class<?> optionsClass)
Return a string describing the usage of the program this method is called from, given the
options declared in the given class.
|
static java.lang.String |
usage(java.lang.Object optionsClass)
Return a string describing the usage of the program this method is called from, given the
options declared in the given object.
|
static java.lang.String |
usage(java.lang.Object[] optionsClasses)
Return a string describing the usage of the program this method is called from, given the
options declared in the given set of objects.
|
@ArgumentParser.Option(name="option_classes", gloss="Fill options from these classes") public static java.lang.Class<?>[] optionClasses
@ArgumentParser.Option(name="threads", gloss="Number of threads on machine") public static int threads
@ArgumentParser.Option(name="host", gloss="Name of computer we are running on") public static java.lang.String host
public static void fillOptions(java.lang.Class<?>[] classes, java.util.Properties options)
classes
- The classes to populate static ArgumentParser.Option
-tagged fields in.options
- The properties to use to fill these fields.public static void fillOptions(java.lang.Class<?>[] optionClasses, java.util.Properties props, java.lang.String... args)
ArgumentParser.Option
-tagged fields in the given classes with the given Properties.
Then, fill in additional (or overwrite existing) properties with the given (String) command-line arguments.optionClasses
- The classes to populate static ArgumentParser.Option
-tagged fields in.props
- The properties to use to fill these fields.args
- The command-line arguments to use to fill in additional properties.public static void fillOptions(java.lang.Class<?>[] classes, java.lang.String... args)
ArgumentParser.Option
-tagged fields in
the given classes.classes
- The classes to populate static ArgumentParser.Option
-tagged fields in.args
- The command-line arguments to use to fill in additional properties.public static void fillOptions(java.lang.Class<?> clazz, java.util.Properties options)
clazz
- The class to populate static ArgumentParser.Option
-tagged fields in.options
- The properties to use to fill these fields.public static void fillOptions(java.lang.Class<?> clazz, java.util.Properties props, java.lang.String... args)
clazz
- The class to populate static ArgumentParser.Option
-tagged fields in.props
- The properties to use to fill these fields.args
- Additional command-line options to fill these fields.public static void fillOptions(java.lang.Class<?> clazz, java.lang.String... args)
clazz
- The class to populate static ArgumentParser.Option
-tagged fields in.args
- The command-line arguments to use to fill these fields.public static void fillOptions(java.util.Properties props)
props
- The properties to use to fill fields in the various classes.public static void fillOptions(java.lang.String... args)
args
- The command-line arguments to use to fill options.public static void fillOptions(java.util.Properties props, java.lang.String... args)
ArgumentParser.Option
-tagged fields in the given classes with the given Properties.
Then, fill in additional (or overwrite existing) properties with the given (String) command-line arguments.
Note that this may take a while if the classpath is large.props
- The properties to use to fill fields in the various classes.args
- The command-line arguments to use to fill in additional properties.public static void fillOptions(java.lang.Object[] instances, java.util.Properties options)
ArgumentParser.Option
-tagged fields in the given set of objects with the given
properties.instances
- The object instances containing ArgumentParser.Option
-tagged fields which we should fill.options
- The properties to use to fill these fields.public static void fillOptions(java.lang.Object[] instances, java.lang.String[] args)
ArgumentParser.Option
-tagged fields in the given set of objects with the given
command-line arguments.instances
- The object instances containing ArgumentParser.Option
-tagged fields which we should fill.args
- The command-line arguments to use to fill these fields.public static void fillOptions(java.lang.Object instance, java.util.Properties options)
ArgumentParser.Option
-tagged fields in the given object with the given
properties.instance
- The object instance containing ArgumentParser.Option
-tagged fields which we should fill.options
- The properties to use to fill these fields.public static void fillOptions(java.lang.Object instance, java.util.Properties props, java.lang.String... args)
instance
- The object instance containing ArgumentParser.Option
-tagged fields which we should fill.props
- The properties to use to fill these fields.args
- Additional command-line options to fill these fields.public static void fillOptions(java.lang.Object instance, java.lang.String... args)
ArgumentParser.Option
-tagged fields in the given object with the given
command-line arguments.instance
- The object instance containing ArgumentParser.Option
-tagged fields which we should fill.args
- The command-line arguments to use to fill these fields.public static void fillOptions(java.lang.Object subcomponent, java.lang.String subcomponentName, java.util.Properties props)
parse
then it takes a property parse.maxlen
for instance.subcomponent
- The subcomponent to fill options for.subcomponentName
- The name of the subcomponent, for parsing properties.props
- The properties to fill the options in the subcomponent with.public static java.util.List<java.lang.String> listOptions(java.lang.Class c)
ArgumentParser.Option
's for provided Classc
- The Class to analyzeArgumentParser.Option
namespublic static java.lang.String usage(java.lang.Class[] optionsClasses)
optionsClasses
- The classes defining the options being used by this program.public static java.lang.String usage(java.lang.Object[] optionsClasses)
optionsClasses
- The objects defining the options being used by this program.public static java.lang.String usage(java.lang.Class<?> optionsClass)
optionsClass
- The class defining the options being used by this program.public static java.lang.String usage(java.lang.Object optionsClass)
optionsClass
- The object defining the options being used by this program.