public class CommandLineProcessor extends Object
| Constructor and Description |
|---|
CommandLineProcessor() |
| Modifier and Type | Method and Description |
|---|---|
List<String> |
getFiles()
Get the non option (file) arguments that were gathered by the method
process(). |
Map<String,String> |
getOptions()
Get the options that were gathered by the method
process(). |
String |
option(String name)
Get a command line option value.
|
Boolean |
optionExists(String name)
Decides if a command line option was specified on the command line or
not.
|
void |
process(String[] args)
Parses the command line to discover all the 'option' arguments and all
the 'file' arguments.
|
public Map<String,String> getOptions()
process().public Boolean optionExists(String name)
Should only be called after the method process() was invoked.
name - the name of the option we are looking fortrue if the option was specified on the command line, and
false if the option was not specifiedpublic String option(String name)
Should only be called after the method process() was invoked.
name - the name of the option we are looking forpublic List<String> getFiles()
process().public void process(String[] args)
-- then this is a
--arg=valueformatted argument. The value and the name of the option are separated using an
= equal sign and thus present in the same command line
argument.
When the argument starts with single dash - (and not double dash
--) then it is a
-arg valuetype argument. The difference is that in this case the argument value is the next command line argument separated by space on the command line from the name of the options.
When an argument does not start with dash then this is a 'file' parameter
and it gets into the files collection.
When a 'file' argument starts with a dash '-' then it has to be preceded
with two dashes. For example -specialFile has to be written as
---specialFile.
The order of the parameters and the way they are specified ( -- or - ) is not preserved. The order of 'file' arguments is reserved in the array.
args - the arguments passed to the main functionCopyright © 2015. All Rights Reserved.