public abstract class CommandLineBase extends Object
| Modifier and Type | Field and Description |
|---|---|
static boolean |
HAS_NO_VALUE |
static boolean |
HAS_VALUE |
static String |
LIST_SEPARATOR |
static boolean |
NOT_REQUIRED |
static String |
OPT_HELP |
static String |
OPT_INFOLEVEL |
static boolean |
REQUIRED |
| Constructor and Description |
|---|
CommandLineBase() |
CommandLineBase(String sCommandName)
create a new command line instance and name it.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addOption(String sShort,
String sLong,
boolean bHasValue,
boolean bRequired,
String sDescription)
define a new option for this command line.
|
void |
addStdOpt_Help()
add the predefined option for showing a help to this instance.
|
void |
addStdOpt_InfoLevel()
add a predefined option for logging to this instance
|
String |
getInfoLevel() |
protected String |
getOptionValue(String sShort) |
protected List<String> |
getOptionValueAsList(String sShort) |
protected boolean |
hasOption(String sShort) |
protected boolean |
isEmpty() |
boolean |
needsHelp() |
void |
parse(String... lArgs)
parse the list of command line options and set all found
options on this instance.
|
void |
printHelp()
print some help info to stdout.
|
void |
setOptionRequired(String sShort,
boolean bRequired)
define an option as required (mandatory) one.
|
protected abstract void |
verify()
must be overwritten by a derived class to verify the command line more in detail.
|
public static final String OPT_INFOLEVEL
public static final String OPT_HELP
public static final boolean REQUIRED
public static final boolean NOT_REQUIRED
public static final boolean HAS_VALUE
public static final boolean HAS_NO_VALUE
public static final String LIST_SEPARATOR
public CommandLineBase()
public CommandLineBase(String sCommandName)
sCommandName - [IN]
the 'name' of the outside tool using that command line.
Used e.g. for logging and showing help messages.public void addStdOpt_Help()
throws Exception
Exceptionpublic void addStdOpt_InfoLevel()
throws Exception
Exceptionpublic void addOption(String sShort, String sLong, boolean bHasValue, boolean bRequired, String sDescription) throws Exception
sShort - [IN]
the short key for that option.
Used as "-x" later.sLong - [IN]
the long key for that option.
Used as "--xxxxxx" later.bHasValue - [IN]
true if that option must have a value,
false if that option is a boolean option only.bRequired - [IN]
true if that option is mandatory,
false otherwise.sDescription - [IN]
a short description what that option mean.Exceptionpublic void setOptionRequired(String sShort, boolean bRequired) throws Exception
sShort - [IN]
the short key for that option.bRequired - [IN]
the mandatory state (true=mandatory)Exceptionpublic void parse(String... lArgs) throws Exception
lArgs - [IN]
the list of command line arguments to be parsed here.Exceptionpublic String getInfoLevel()
public boolean needsHelp()
throws Exception
Exceptionpublic void printHelp()
throws Exception
Exceptionprotected abstract void verify()
throws Exception
Exceptionprotected boolean isEmpty()
protected String getOptionValue(String sShort) throws Exception
sShort - [IN]
the short key of the option where the value must be returned.Exceptionprotected List<String> getOptionValueAsList(String sShort) throws Exception
sShort - [IN]
the short key of the option where the value must be parsed.ExceptionCopyright © 2016 as-development.net. All rights reserved.