public class StdMainStringArgsLoader extends BaseKeyValuePairLoader implements StandardLoader
String[] args passed to the main(String[] args), which Java
passes from the command line. This is the most common usage, however, your
application may retrieve an array of String's from anywhere to pass
to AndHow at startup.
import org.yarnandtail.andhow.*;
public class MyAppClass {
public static void main(String[] args) {
AndHow.findConfig()
.setCmdLineArgs(args)
.build();
}
}
Passing values from the command line looks like this:
java -jar MyJarName.jar full.name.of.MY_PROPERTY=someValue
Here is a complete example of using command line arguments.
StandardLoader's, this loader is intended to be auto-created
by AndHow. The set of standard loaders and their order can bet set
via the AndHowConfiguration.setStandardLoaders() methods.
Other loaders which don't implement the StandardLoader interface can
be inserted into the load order via the
AndHowConfiguration.insertLoaderBefore/After().KVP_DELIMITER, unknownPropertyAProblem| Constructor and Description |
|---|
StdMainStringArgsLoader()
There is no reason to use the constructor in production application code
because AndHow creates a single instance on demand at runtime.
|
| Modifier and Type | Method and Description |
|---|---|
String |
getLoaderDialect()
The type dialect of the loader.
|
String |
getSpecificLoadDescription()
For this particular load, where was info loaded from?
This may vary from run to run based on config params.
|
boolean |
isFlaggable()
Returns true if this loader supports
FlaggableType's. |
LoaderValues |
load(PropertyConfigurationInternal runtimeDef,
LoaderEnvironment environment,
ValidatedValuesWithContext existingValues)
Builds up a list of LoaderValues by loading property values from a configuration source.
|
getLoaderType, isTrimmingRequiredForStringValues, isUnknownPropertyAProblem, load, setUnknownPropertyAProblemattemptToAdd, attemptToAdd, attemptToAdd, attemptToAddIfNotDuplicate, createValue, findDuplicateProperty, getClassConfig, getConfigSamplePrinter, getInstanceConfig, mapNametoProperty, releaseResourcesclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetClassConfig, getConfigSamplePrinter, getInstanceConfig, getLoaderType, isTrimmingRequiredForStringValues, releaseResourcespublic StdMainStringArgsLoader()
public LoaderValues load(PropertyConfigurationInternal runtimeDef, LoaderEnvironment environment, ValidatedValuesWithContext existingValues)
LoaderLoaders find and load values and associate them with the correct Property. If there is a problem while doing that, they register one or more LoaderProblems in the returned LoaderValues.
Validation of Property values is not Loader's responsibility and will be handled outside this method.
load in interface LoaderruntimeDef - The definition of all known Properties and naming metadata.environment - The environment (System Props, Env vars, fixed values) as
known to the Loader.existingValues - The values already set by prior loaders, which may configure
the behavior of this loader.public String getSpecificLoadDescription()
LoadergetSpecificLoadDescription in interface LoadergetSpecificLoadDescription in class BaseKeyValuePairLoaderpublic String getLoaderDialect()
LoadergetLoaderDialect in interface LoadergetLoaderDialect in class BaseKeyValuePairLoaderpublic boolean isFlaggable()
LoaderFlaggableType's.
Loaders that support FlaggableType give special 'is present' meaning to a property being
present without a value, similar to a 'nix command line flag. If a Loader supports
flags, it should call FlaggableType.parseFlag(String) instead of
ValueType.parse(String) when a Property's ValueType is a FlaggableType.
See FlagProp for an example type.
Note: Returning true from this method is only potentially applicable to Loaders that parse strings. Loaders that directly load from rich values do not parse, so the loader logic would ignore the value here.
Examples:
Loading a non-null value from the properties file entry 'name = ' would be unexpected,
so a properties file Loader should return 'false' here.
However, a command line loader would be expected to support flags, so should return 'true'.
isFlaggable in interface LoaderisFlaggable in class BaseKeyValuePairLoaderCopyright © 2022. All rights reserved.