public class Parm
extends java.lang.Object
Parm
class and its nested classes and interfaces provide a mechanism that allows for convenient and consistent
table based program arguments handling and processing.
The Parm[]
table is matched against the invokation arguments. Errors are reported (such as the absence
of a mandatory field).
If the arguments parse is successful, the class run method is invoked.
Parm
table consists of an array of Parm
objects, each constructed using an anonymous instance of the Parm.PS
interface.
The result of the parse is the customized Parm.Opt
object where each field is populated according to the String[] args
parameter provided to the class main
method.
To improving the readability of the table, the symbolic names are short so that each option can be conveniently specified on one text line.
-key space(s) value
-key
(no trailing value)-defname=value
(no intermediate space, -def used by convention but it could be some other such as -D
Example for below
-brief c:\temp\brief.json.txt -out d:\1\out.xlsx -what basic -red -negfmt "()"
DemoExcel
.
private static class Opt extends Parm.Opt { public String sStr1; public String sOut; public String sInp; public String sWhat; public String sNegFmt; public boolean bRed; } static Opt oOPT = new Opt(); static Parm[] oParms = { new Parm(new Parm.PS(){public void set(String sN) {oOPT.bHelp=true; }}, ".","-h", null, "Generate this Help Information that you are now reading") ,new Parm(new Parm.PS(){public void set(String sN) {oOPT.sBrief=sN;}}, "m","-brief", "brief", "path for Brief output") ,new Parm(new Parm.PS(){public void set(String sN) {oOPT.sOut=sN;}}, "m","-out", "file", "Target output name") ,new Parm(new Parm.PS(){public void set(String sN) {oOPT.sInp=sN;}}, ".","-inp", "file", "input template file") ,new Parm(new Parm.PS(){public void set(String sN) {oOPT.sWhat=sN;}}, "m","-what", "string", "What we are to run") ,new Parm(new Parm.PS(){public void set(String sN) {oOPT.bRed=true; }}, ".","-red", null, "Show negative numbers in red") ,new Parm(new Parm.PS(){public void set(String sN) {oOPT.sNegFmt=sN; }}, ".","-negfmt", "string", "Negative format") ,new Parm(new Parm.PS(){public void set(String sN) {oOPT.addProp(sN);}}, ".","-def", "key=val", "Defined Property string") }; public static void main(String[] sArgs) { oOPT.mainStart(oParms,sArgs,new DemoExcel()); }
Modifier and Type | Class and Description |
---|---|
static class |
Parm.Brief
Brief base class used by PSEC routines.
|
static interface |
Parm.MainRun
The interface class to be implemented by the class that is to be called by the
mainStart method. |
static class |
Parm.Opt
Base class for option set.
|
static interface |
Parm.PS
Interface used to process each option.
|
Constructor and Description |
---|
Parm(Parm.PS oSet,
java.lang.String sFlag,
java.lang.String sParm,
java.lang.String sExtra,
java.lang.String sDesc)
Parm instance constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
printHelp(Parm[] oParms,
java.lang.String sTitle)
List the options.
|
public Parm(Parm.PS oSet, java.lang.String sFlag, java.lang.String sParm, java.lang.String sExtra, java.lang.String sDesc)
The constructor
has 4 input parameters.
set
method.oSet
- The anonymous used to transform the input data.
sFlag
- The mandatory flag.sParm
- The external key string used to recognize the parameter.sExtra
- A string to indicate the value type.sDesc
- A brief description that helps the user know the meaning and format of the data.public static void printHelp(Parm[] oParms, java.lang.String sTitle)
oParms
- the Parm[]
table;sTitle
- The list title.