@Deprecated public abstract class MainCmd extends java.lang.Object implements MainCmd_ifc
Arguments are used since 2020-03 for more powerful and simple command line argument parsing.
LogMessage is used as interface for outputs.
LogMessageStream supports proper also output to console and files.
#writeAboutInfo() and #writeHelpInfo().
SampleCmdLine.
cmd args >myOutput or one can use a pipe
construction like cmd args | cmd2 args. In that cases the outputs written with System.out
are written to the given channel (usual a file) respectively they are stored in a pipe to provide the input for the
next command. In this cases usual the standard output System.out is redirected but not the error output.
#report(int, String) etc.
#report(int, String) or #reportln(int, String) can be used
from an application instead System.out.println(....).
The first parameter controls whether the output is written to console channel or to the report file. With the
command line arguments --report=FILE and --rlevel=WDR parsed as standard arguments
the usage of levels and the file is controlled without additional programming effort.
With that approach a output file 'report file' is created anyway in a command line application. The report file
contains the same or more information than the console output. A command line application doesn't require the
redirection in a file to get its output persistently. A persistent output is available anyway with the report file.
#writeInfo(String), #writeWarning(String) and #writeError(String) can be used
to output some things as information, warning or error in the application. The output is categorized to one of this
three levels.
This information is written to the console output anyway.
It depends on the 3. position 'W' of the --relevl=WDR whether this output is written in the report file.
writeError(String, Throwable).
MainCmdLogging_ifc (older version Report)
supports this system.
LogMessage.error to LogMessage.fineDebug. But in complex software a module may output
something independent of the necessity of output of information of another module.
MainCmdLogging_ifc
because it may be realized as a special interface.
MsgDispatcher.setOutputRange(int, int, int, int, int)
LogMessage interface. The MainCmd
implements the LogMessage interface. It is a super interface of MainCmdLogging_ifc.
The implementation of the LogMessage in MainCmd can redirect the message to the message dispatcher or any
other implementor given with setLogMessageDestination(LogMessage). The default behaviour is writing
the message via #reportln(int, String) to console and the report file. Wherby the ident number is taken from
the message indent number if it is 1..6 (LogMessage.error to LogMessage.fineDebug).
All other ident numbers are written with reportln(LogMessage.info, line).
The line contains the message ident number and the time of creation of the message.
That is the simple adaption from the LogMessage approach without using of a message dispatching system.
MsgDispatcher can be established. One can
invoke setLogMessageDestination(LogMessage) and use the channels getLogMessageErrorConsole(),
getLogMessageOutputConsole() and getLogMessageOutputFile() from this class as destination channels
for the MessageDispatcher.
MsgPrintStream can be used to create numbers automatically.
With them the simple System.out.printf("message text\n", parameter) is converted to a LogMessage invocation.
The ident numbers of the messages are created automatically in a given number range or it can be set by a control String.
System.out.printf("message text\n", parameter) is sufficient to output something
and to work with the message dispatching and output management system. The dispatching is support with
ReportWrapperLog. This is the adaption from
the older report approach to the message system.
MainCmd_ifc or its super interface,
the MainCmdLogging_ifc. One can use both, the MainCmd_ifc#report(int, String) invocation and the
LogMessage#sendMsg(int, String, Object...) approach.
MsgDispatcher class as LogMessage reference.
One should organize and use the message ident numbers.
System.out.print.... Therewith independent
sources from any vishia classes can be written. Using a format System.out.printf("Module - message; text %d %f\n", value1, value2);LogMessage if the software is specialized for
message output, and to use the third approach, System.out for any other independent modules. The organization of both
approaches to use the message system can be done at a centralized point in software. The example SampleCmdLine
presents example outputs with that approaches.
org.vishia.gral.area9.GralArea9MainCmd to a class which implements
the outputs on a GUI window. The methods supporting command line things
are adapted there for a GUI (Graphical User Interface) -style application. In the GUI frame the user used the same
interface MainCmd_Ifc to do something with the applications frame.
---|> means an inherition
<>--> means a composition or aggregation
----> means a association
+-------------+ +-------------+ +-------------+
| |------|>| MainCmd |------|>| MainCmd_Ifc |
|UserMainClass| +-------------+ +-------------+
| | ^
| | +-------------+ main |
| |<>----->| UserClasses |---------------+
+-------------+ +-------------+
in cmdlines:
class UserMainClass extends MainCmd
{ final UserClasses userClasses = new UserClasses(this); //... the user's classes
}
class UserClasses
{ final MainCmd_Ifc main; //the aggregation to Main
UserClasses(MainCmd_Ifc main)
{ this.main = main;
}
}
The UserMainClass based on MainCmd as superclass, MainCmd implements MainCmd_Ifc.
All composite classes from UserMainclass may known the MainCmd instance respective the UserMainClass instance
via the interface MainCmd_Ifc.
With this interface the user can access at all capabilities of support of command line things,
implemented cardinally in MainCmd, but overwriteable from the user in his UserMainClass.| Modifier and Type | Class and Description |
|---|---|
static class |
MainCmd.Argument
Deprecated.
the newer form is
Arguments, use this for new development. |
private class |
MainCmd.LogMessageImplConsole
Deprecated.
Inner class to send a LogMessage to the
outConsole. |
(package private) class |
MainCmd.LogMessageImplErrConsole
Deprecated.
|
(package private) class |
MainCmd.LogMessageImplFile
Deprecated.
|
static interface |
MainCmd.SetArgument
Deprecated.
the newer form is
Arguments.SetArgument, use this for new development. |
private class |
MainCmd.ShowCmdOutput
Deprecated.
Class to write any readed stream to the output, running in a separate thread.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<MainCmd.Argument> |
argList
Deprecated.
|
protected boolean |
bHelpIswritten
Deprecated.
|
protected java.lang.String[] |
cmdLineArgs
Deprecated.
array of arguments from command line
|
java.lang.String |
currdir
Deprecated.
|
protected java.text.SimpleDateFormat |
dateFormatMsg
Deprecated.
|
java.io.PrintStream |
errCmdline
Deprecated.
Preserve the original System.out and System.err on construction.
|
private java.lang.Appendable |
errConsole
Deprecated.
Channels for output and error output of the main program.
|
FileWrite |
fReport
Deprecated.
The report file.
|
private int |
iArgs
Deprecated.
number of the argument is parsing
|
protected static short |
kError_writeInfoDirectly
Deprecated.
|
protected static short |
kInfo_writeInfoDirectly
Deprecated.
Some bits to mark the kind of output
|
static short |
kInfoln_writeInfoDirectly
Deprecated.
|
protected static short |
kWarning_writeInfoDirectly
Deprecated.
|
java.util.List<java.lang.String> |
listAboutInfo
Deprecated.
List of strings contents about Info in form of lines.
|
java.util.List<java.lang.String> |
listHelpInfo
Deprecated.
List of strings contents help Info in form of lines.
|
(package private) MainCmd.LogMessageImplConsole |
logMessageConsole
Deprecated.
|
(package private) MainCmd.LogMessageImplErrConsole |
logMessageErrConsole
Deprecated.
|
(package private) MainCmd.LogMessageImplFile |
logMessageFile
Deprecated.
|
protected LogMessage |
logMessageImplReport
Deprecated.
Instance to send a LogMessage to the Log interface of maincmd.
|
protected static short |
mError_writeInfoDirectly
Deprecated.
If this bit is setted in param kind of writeDirectly
an error is to be outputted
|
static short |
mNewln_writeInfoDirectly
Deprecated.
If this bit is setted in param kind of writeDirectly
a newline should be inserted at begin of output
|
protected MsgRedirectConsole |
msgDisp
Deprecated.
A standard variant of the
MsgDispatcher for all application,
which redirects System.out and System.err. |
protected static short |
mWarning_writeInfoDirectly
Deprecated.
If this bit is setted in param kind of writeDirectly
a warning is to be outputted
|
int |
nLevelDisplayToReport
Deprecated.
writeError(), writeWarning(), writeInfo() are also reported if the level is equal or greater than 1,2,3
|
int |
nLogLevel
Deprecated.
All reports with a level less than or equal this level will be reported.
|
private int |
nMaxErrorLevel
Deprecated.
The maximum of the value given with setExitErrorLevel
|
int |
nReportLevelDisplay
Deprecated.
All reports with a level less than or equal this level will be written on display.
|
java.io.PrintStream |
outCmdline
Deprecated.
Preserve the original System.out and System.err on construction.
|
private java.lang.Appendable |
outConsole
Deprecated.
Channels for output and error output of the main program.
|
private LogMessage |
redirectLogMessage
Deprecated.
|
private static java.lang.String |
report_spaces
Deprecated.
access to some spaces via Report.spaces.substring(0,n)
|
private java.lang.String |
sFileLog
Deprecated.
|
private static MainCmd |
singleton
Deprecated.
Because this class is used as superclass for a command line Java invocation,
it is possible to store the only one instance for a static getter method.
|
static java.lang.String |
sVersion
Deprecated.
Version, history and license.
|
anytime, eventOrder, exitSuccessfull, exitUserAbort, exitWithArgumentError, exitWithErrors, exitWithFileProblems, exitWithNotes, exitWithWarnings, fineEventOrder, interested, versiondateFormat, debug, error, fineDebug, fineInfo, info, minSecondsFormat, mNeverOutputToDisplay, mReportLevel, warning| Modifier | Constructor and Description |
|---|---|
protected |
MainCmd()
Deprecated.
Empty Constructor of the main class.
|
protected |
MainCmd(MainCmd.Argument[] argList)
Deprecated.
|
protected |
MainCmd(MainCmd.Argument[] argList,
java.lang.String[] args)
Deprecated.
Constructor of the main class.
|
protected |
MainCmd(java.lang.String[] args)
Deprecated.
Constructor of the main class.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addAboutInfo(java.lang.String sInfo)
Deprecated.
Adds a about info-line to the internal list.
|
void |
addArgument(MainCmd.Argument[] list)
Deprecated.
Adds arguments inclusively help info for this application.
|
protected void |
addHelpInfo(java.lang.String sInfo)
Deprecated.
Adds a help info-line to the internal list.
|
protected void |
addMsgConfig(java.lang.String sFileName)
Deprecated.
|
protected void |
addStandardHelpInfo()
Deprecated.
Adds the help info for standard arguments.
|
java.lang.Appendable |
append(char c)
Deprecated.
|
java.lang.Appendable |
append(java.lang.CharSequence csq)
Deprecated.
|
java.lang.Appendable |
append(java.lang.CharSequence csq,
int start,
int end)
Deprecated.
|
protected void |
callWithoutArguments()
Deprecated.
Invoked from parseArguments if no argument is given.
|
protected abstract boolean |
checkArguments()
Deprecated.
Checks the arguments after parsing from command line, test of consistence.
|
void |
close()
Deprecated.
A call of this method closes the devices, which processed the message.
|
java.lang.String |
currdir()
Deprecated.
Returns that current directory which is given by argument "--currdir=value" or which was
setcurrdir(String). |
int |
executeCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String[] cmd,
java.lang.String input,
int nReportLevel,
java.lang.Appendable output,
java.lang.Appendable errOut)
Deprecated.
Executes a command line call maybe as pipe, waiting for finishing..
|
int |
executeCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String cmd,
java.lang.String input,
int nReportLevel,
java.lang.Appendable output,
java.lang.Appendable errOut)
Deprecated.
Executes a command line call maybe as pipe, waiting for finishing..
|
int |
executeCmdLine(java.lang.String[] cmd,
int nReportLevel,
java.lang.Appendable output,
java.lang.String input)
Deprecated.
|
int |
executeCmdLine(java.lang.String[] cmd,
java.lang.ProcessBuilder processBuilder,
int nReportLevel,
java.lang.Appendable output,
java.lang.String input)
Deprecated.
|
int |
executeCmdLine(java.lang.String cmd,
int nReportLevel,
java.lang.Appendable output,
java.lang.String input)
Deprecated.
Execute a command invoke a cmdline call, implements MainCmd_Ifc.
|
int |
executeCmdLine(java.lang.String cmd,
java.lang.ProcessBuilder processBuilder,
int nReportLevel,
java.lang.Appendable output,
java.lang.String input)
Deprecated.
|
void |
exit()
Deprecated.
Exits the cmdline application with the maximum of setted exit error level.
|
void |
flush()
Deprecated.
A call of this method causes an activating of transmission of all messages since last flush.
|
void |
flushReport()
Deprecated.
Writes the content in the physical medium.
|
protected java.lang.String |
getArgument(int pos)
Deprecated.
Returns the argument contents.
|
int |
getExitErrorLevel()
Deprecated.
get the maximum of errorLevel setted with setExitErrorLevel().
|
static MainCmdLogging_ifc |
getLogging_ifc()
Deprecated.
Gets the singleton MainCmd instance as Logging interface or returns a
MainCmdLoggingStream
instance if this class is not instanciated. |
LogMessage |
getLogMessageErrorConsole()
Deprecated.
Gets a LogMessage error output.
|
LogMessage |
getLogMessageOutputConsole()
Deprecated.
Gets a LogMessage output.
|
LogMessage |
getLogMessageOutputFile()
Deprecated.
Gets a LogMessage output.
|
java.lang.String |
getReportFileName()
Deprecated.
Returns the name of the report file to write out as info.
|
int |
getReportLevel()
Deprecated.
Test wether the report is in the level.
|
int |
getReportLevelFromIdent(int ident)
Deprecated.
gets the associated report level to a report identifier.
|
boolean |
isOnline()
Deprecated.
Checks whether the message output is available.
|
void |
openReportfile(java.lang.String sFileReport,
boolean bAppendReport)
Deprecated.
|
boolean |
parseArguments()
Deprecated.
Parses the cmdLine-arguments.
|
boolean |
parseArguments(java.lang.String[] args)
Deprecated.
Parses the cmdLine-arguments.
|
java.lang.String |
replaceEnv(java.lang.String argval)
Deprecated.
|
void |
report(java.lang.CharSequence sInfo,
java.lang.Throwable exception)
Deprecated.
Reports an exception.
|
private void |
report(java.lang.CharSequence sInfo,
java.lang.Throwable exception,
boolean bWrittenOnDisplay)
Deprecated.
Internal method to write an exception to report.
|
void |
report(int nLevel,
java.lang.CharSequence ss)
Deprecated.
report appending on exist line.
|
void |
reportln(int nLevel,
java.lang.CharSequence ss)
Deprecated.
report begins at a new a line
|
void |
reportln(int nLevel,
int nLeftMargin,
java.lang.CharSequence ss)
Deprecated.
report begins at a new a line with left margin
|
boolean |
sendMsg(int identNumber,
java.lang.CharSequence text,
java.lang.Object... args)
Deprecated.
Sends a message.
|
boolean |
sendMsgTime(int identNumber,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
java.lang.Object... args)
Deprecated.
Sends a message.
|
(package private) void |
sendMsgTimeToAppendableDst(java.lang.Appendable dst,
int identNumber,
int reportLevel,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
java.lang.Object... args)
Deprecated.
|
boolean |
sendMsgVaList(int identNumber,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
Va_list args)
Deprecated.
Sends a message.
|
java.lang.String |
setcurrdir(java.lang.String newDir)
Deprecated.
Sets the Property
currdir() for this instance. |
void |
setExitErrorLevel(int level)
Deprecated.
set the exitErrorLevel of the maximum of given level of every call.
|
void |
setLogMessageDestination(LogMessage log)
Deprecated.
Redirects the LogMessage implementation of this class to the given implementor.
|
void |
setOutputChannels(java.lang.Appendable outP,
java.lang.Appendable errP)
Deprecated.
Sets destinations for output and error output.
|
int |
setReportLevel(int newLevel)
Deprecated.
Set another level inside programming.
|
void |
setReportLevelToIdent(int nLevel,
int nLevelActive)
Deprecated.
Sets a dedicated level number to the known output priorities.
|
int |
startCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String cmd)
Deprecated.
Starts a command invocation for a independent window.
|
int |
startCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String[] cmd)
Deprecated.
Starts a command invocation for a independent window.
|
int |
switchToWindowOrStartCmdline(java.lang.ProcessBuilder processBuilder,
java.lang.String sCmd,
java.lang.String sWindowTitle)
Deprecated.
Searches the window for the already running process
or starts the process with command invocation for a independent window.
|
protected boolean |
testArgument(java.lang.String argc,
int nArg)
Deprecated.
Tests one argument, called from parseArguments() on every argument excluding standard arguments -r and -rlevel.
|
void |
writeAboutInfo(java.lang.Appendable out)
Deprecated.
prints the help info to the console output.
|
void |
writeDirectly(java.lang.CharSequence sInfo,
short kind)
Deprecated.
Writes the given sInfo to the output channels
#out or #err. |
void |
writeError(java.lang.CharSequence sInfo)
Deprecated.
Writes an error line, implementation of MainCmd_Ifc.
|
void |
writeError(java.lang.String msg,
java.lang.Object... args)
Deprecated.
Writes a beginning new line with the prepared text to an error output.
|
void |
writeError(java.lang.String sInfo,
java.lang.Throwable exception)
Deprecated.
Writes an error line with exception info, implementation of MainCmd_Ifc.
|
void |
writeErrorAdd(java.lang.String msg,
java.lang.Object... args)
Deprecated.
Writes an additional information for the error message after the already outputted error line in the same line.
|
void |
writeErrorDirectly(java.lang.CharSequence sInfo,
java.lang.Throwable exception)
Deprecated.
Writes an error line by console application directly to System.err.println
with the String "EXCEPTION: " before and the exception message.
|
void |
writef(java.lang.String msg,
java.lang.Object... args)
Deprecated.
Writes the prepared text to the log as information.
|
void |
writeHelpInfo(java.io.File outfile)
Deprecated.
prints the help info to the console output.
|
void |
writeInfo(java.lang.CharSequence sInfo)
Deprecated.
Writes an information, implementation of MainCmd_Ifc.
|
void |
writeInfo(java.lang.String msg,
java.lang.Object... args)
Deprecated.
Writes the prepared text to the log as information.
|
void |
writeInfoAdd(java.lang.String msg,
java.lang.Object... args)
Deprecated.
Writes an additional information for the info message after the already output info line in the same line.
|
void |
writeInfoln(java.lang.CharSequence sInfo)
Deprecated.
Writes an information line, implementation of MainCmd_Ifc.
|
void |
writeStackTrace(java.lang.Exception exception)
Deprecated.
write out the stacktrace from a exception.
|
void |
writeWarning(java.lang.CharSequence sInfo)
Deprecated.
Writes an warning line, implementation of MainCmd_Ifc.
|
void |
writeWarning(java.lang.String msg,
java.lang.Object... args)
Deprecated.
Writes a beginning new line with the prepared text to an standard or warning output.
|
void |
writeWarningAdd(java.lang.String msg,
java.lang.Object... args)
Deprecated.
Writes an additional information for the warning message after the already outputt warning line in the same line.
|
static void |
XXXassertion(boolean condition)
Deprecated.
Its a helper to set a breakpoint for assert
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitmsgSec, timeCurr, timeMsgpublic static java.lang.String sVersion
writeError(String, Throwable) instead Exception etc.
currdir() and currdir. It can be used by an application.
Note that the System.setProperty("user.dir", value) affects the whole JVM. A MainCmd may be invoked
only as a part of an Java application. Therefore the currdir is local valid. Note that the currdir
and the System.setProperty("user.dir",...) both don't affects the operation system.
getLogging_ifc(), usage MainCmd in any Java class without forwarded argument.
#sendMsgTimeToAppendableDst(Appendable, int, int, OS_TimeStamp, String, Object...)
catches a IllegalFormatException
testArgument(String, int) emptyArg supported, was commented.
MsgRedirectConsole to the main instance.
Therewith the Conversion of System.out.println(...) and System.err... can be used in all applications.
The first advantage: All messages have a time stamp.
addArgument(Argument[]), see description of MainCmd.Argument
addArgument(Argument[]),especially old: setArguments(..)
is renamed to addArgument(). It is prepared that an inherited class's main(...) can add some more arguments
than the base class.
getLogMessageOutputConsole() etc.
addArgument(Argument[]) as new method to bundle argument query and help text.
getLogMessageErrorConsole()
setOutputChannels(Appendable, Appendable). All outputs are redirect-able now.
Used for output in a graphical text box.
executeCmdLine(ProcessBuilder, String, String, int, Appendable, Appendable)
has produced a problem because 2 spaces are given in the args instead of one. There was an empty argument therefore,
which has had a negative effect to a called command (it was "bzr add", an empty argument forces addition of all files
though the next arguments had contain some named files). The problem is solved with using a more complex algorithm
to split arguments as a simple String.split(" "). See #splitArgs(String).
protected final java.util.List<MainCmd.Argument> argList
private static MainCmd singleton
MainCmdLogging_ifc
or MainCmd_ifc it can use this instance without a forwarded argument.public FileWrite fReport
public int nLogLevel
private java.lang.String sFileLog
public java.lang.String currdir
public int nReportLevelDisplay
Report#writeInfo(String) etc. writes to display also if this attribute is 0.public int nLevelDisplayToReport
public java.util.List<java.lang.String> listHelpInfo
public java.util.List<java.lang.String> listAboutInfo
private int nMaxErrorLevel
protected java.lang.String[] cmdLineArgs
private int iArgs
protected boolean bHelpIswritten
private static final java.lang.String report_spaces
private LogMessage redirectLogMessage
public final java.io.PrintStream outCmdline
public final java.io.PrintStream errCmdline
private java.lang.Appendable outConsole
private java.lang.Appendable errConsole
protected MsgRedirectConsole msgDisp
MsgDispatcher for all application,
which redirects System.out and System.err.protected java.text.SimpleDateFormat dateFormatMsg
protected static final short kInfo_writeInfoDirectly
public static final short kInfoln_writeInfoDirectly
protected static final short kWarning_writeInfoDirectly
protected static final short kError_writeInfoDirectly
public static final short mNewln_writeInfoDirectly
protected static final short mWarning_writeInfoDirectly
protected static final short mError_writeInfoDirectly
protected LogMessage logMessageImplReport
MainCmd.LogMessageImplConsole logMessageConsole
MainCmd.LogMessageImplErrConsole logMessageErrConsole
MainCmd.LogMessageImplFile logMessageFile
protected MainCmd()
#setArguments(Argument[]) and parseArguments(String[])
instead of MainCmd(Argument[], String[]).
System.out and System.err
are preserved inside this class in outCmdline and errCmdline.
One can redirect System.setOut(PrintStream) and ...setErr(...) without changing of the MainCmd
outputs after construction of this. Especially the System.out and System.err can be redirected to the Message system
using MsgPrintStream and MsgDispatcher with usage of
the console outputs preserved in this class using getLogMessageErrorConsole(), getLogMessageOutputConsole()
and getLogMessageOutputFile() of this class.protected MainCmd(java.lang.String[] args)
protected MainCmd(MainCmd.Argument[] argList)
protected MainCmd(MainCmd.Argument[] argList, java.lang.String[] args)
public void setLogMessageDestination(LogMessage log)
MsgDispatcher. By default the logmessage capability
of this class is implemented in that kind that all messages with the ident numbers from 1 to 6 are output
in the same form as #reportln(int, String) and all other ident numbers are written with
reportln(LogMessage.info, messageString). The message dispatcher can be help
to select the output channels of the messages.log - public void addArgument(MainCmd.Argument[] list)
addHelpInfo(String)
to the correct sequence.list - see MainCmd.Argumentprotected void addStandardHelpInfo()
addHelpInfo("--about show the about info");
addHelpInfo("--help[=helpfile] show the help info");
addHelpInfo("--currdir=PATH Set the currdir variable.");
addHelpInfo("--log=FILE write the report (log) into the given file, create or clear the file.");
addHelpInfo("-+log=FILE add to the end of given file or create the report file.");
addHelpInfo("--loglevel=R set the level of report, R is number from 1 to 6.");
addHelpInfo("--loglevel=DR also write reports upto level D on display, sample: ..-rlevel:24");
addHelpInfo("--loglevel=WDR write output also in report, W is nr from 1 to 3 (error, warning, info");
protected void addHelpInfo(java.lang.String sInfo)
writeHelpInfo()
called if the argument --help is given or without arguments. .info - String contains 1 line of a help Info.protected void addAboutInfo(java.lang.String sInfo)
info - String contains 1 line of a help Info.public void writeHelpInfo(java.io.File outfile)
public void writeAboutInfo(java.lang.Appendable out)
public final boolean parseArguments()
throws java.text.ParseException
java.text.ParseExceptionparseArguments(String [] args)public final boolean parseArguments(java.lang.String[] args)
throws java.text.ParseException
public static void main(String[] args){
Args argData = new Args();
Cmdline cmd = new Cmdline(argData);
boolean bOk;
try{ bOk = cmd.parseArguments(args);
} catch(ParseException exc){
cmd.setExitErrorLevel(MainCmd.exitWithArgumentError);
bOk = false;
}
if(bOk) {
UserClass main = new UserClass(argData.x, argData.y);
main.exec(argData.z);
}
cmd.exit();
}
Within this pattern the parsing of the arguments is independent of the user class.
It may be an advantage of architecture of the user class. Some argument values
can be used as initial values on construction of the user class. They can be stored there in 'final' Associations.
#setArguments(Argument[]) to define which arguments are used in which kind.
In the older form (till 2012), the user was requested to override this method.
addStandardHelpInfo().
>cmd -a arg1 --@file -x argx results in the followed arguments:-a arg1 arguments-from-file-lines -x argx
testArgument(String, int) inside.
That method checks any argument, see there. If that method returns false,
a #writeError(String) with a matched text is called and a ParseException("", N) ist thrown, N is the
number of the argument.
Standard arguments are parsed here, see addStandardHelpInfo().
On end the method checkArguments() is called if other then standard arguments are given.
If it returns false, an ParseException("", 0) is thrown.
The user should had write an output message with writeError() inside its checkArguments()arg - The given arguments from command line invocation.checkArguments() was called.java.text.ParseExceptionaddArgument(Argument[])public void openReportfile(java.lang.String sFileReport,
boolean bAppendReport)
throws java.io.FileNotFoundException
openReportfile in interface MainCmdLogging_ifcjava.io.FileNotFoundExceptionprotected abstract boolean checkArguments()
protected void callWithoutArguments()
throws java.text.ParseException
java.text.ParseExceptionprotected java.lang.String getArgument(int pos)
pos - position of the beginning of the information in a argument. In the sample above use the value 2.protected boolean testArgument(java.lang.String argc,
int nArg)
throws java.io.FileNotFoundException
#setArgumentList(Argument[])argc - The argument to testnArg - number of argument, the first argument is numbered with 1.java.io.FileNotFoundExceptionjava.text.ParseException - The method may thrown this exception if a conversion error or such other is thrown.public java.lang.String replaceEnv(java.lang.String argval)
public java.lang.String currdir()
setcurrdir(String).
Note that the currdir is not checked whether it is valid and existing.
It should be an existing valid normalized absolute path. The application should check it
because the path may be existing and removed than. There is no guarantee possible.
File myFile = new File(currdir(), "relative/path");Note that the
System.setProperty("user.dir", currdir);
has a global effect for the running JVM, but it has no effect to the operation system. It means
System.setProperty("user.dir", "/My/Workingplace");
File myFile = new File("relative.path");
String abspath = myFile.getAbsolutePath();
Does not work proper! If the relative File is used to open anything, the open process is done on the
operation system level. But the operation system does not know anything about a changed current dir.
But the File.getAbsolutePath() works with the JVM-global setting of "user.dir". That is confusion,
which depends on the history and technique.
currdir in interface MainCmd_ifcpublic java.lang.String setcurrdir(java.lang.String newDir)
currdir() for this instance.setcurrdir in interface MainCmd_ifcnewDir - any String which should contain an absolute normalized valid path to an existing directory.
The path is not tested here, it should be tested in the user's application because it may be depending
on any user's condition.currdir().public void setExitErrorLevel(int level)
setExitErrorLevel in interface MainCmdLogging_ifclevel - Errorlevel how defined in Report, 0 is the lowest level (successfull), >0 is worse.public int getExitErrorLevel()
getExitErrorLevel in interface MainCmdLogging_ifcpublic void setOutputChannels(java.lang.Appendable outP,
java.lang.Appendable errP)
System.out and System.err
on construction of this class are set. That is the console output if this class is construct during processing
a public main(String[] args)-routine, this routine is invoked froma cmd line call and the output and error
channels of the command line are not redirected.
#writeDirectly(String, short) and from the
implementations of getLogMessageOutputConsole() and getLogMessageErrorConsole().
If the
It is recommended that this channels
shall be unchanged, it means this method should not used. It is reasonable to use this method only for tests.
MsgPrintStream
and that output is directed to this class, and then setOuputChannels(System.out, System.err) is set,
it escalates in a self-calling loop with stack overflow.setOutputChannels in interface MainCmdLogging_ifcoutP - Destination for output. If null, current output isn't change.errP - Destination for error output. If null, current output isn't change.public void exit()
public int executeCmdLine(java.lang.String cmd,
int nReportLevel,
java.lang.Appendable output,
java.lang.String input)
executeCmdLine in interface MainCmd_ifccmd - String represents the command with all arguments. The arguments must be separated by exactly one space.
The rest of paramter and return see executeCmdLine(String[], ...).@Deprecated
public int executeCmdLine(java.lang.String[] cmd,
int nReportLevel,
java.lang.Appendable output,
java.lang.String input)
executeCmdLine in interface MainCmd_ifccmd - String with the separeted parts of the command. cmd[0] is the command to invoke.nReportLevel - Determines the kind of writing the output. Possible values are 1..6 using Report.error to Report.fineInfo
and -1..-3 using -Report.error to -report.info (with a negativ sign!). On negativ values the
report is written to display with the write..()-methods of this interface, with the
positive value, the report is written to Report.report..()-Methods.output - If not null, than the stdout is written in this Buffer. If null, the stdout is written to report.input - If not null, this input is send to the cmdline process. If null, no input is send.@Deprecated
public int executeCmdLine(java.lang.String cmd,
java.lang.ProcessBuilder processBuilder,
int nReportLevel,
java.lang.Appendable output,
java.lang.String input)
@Deprecated
public int executeCmdLine(java.lang.String[] cmd,
java.lang.ProcessBuilder processBuilder,
int nReportLevel,
java.lang.Appendable output,
java.lang.String input)
cmd - processBuilder - nReportLevel - output - input - public int executeCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String cmd,
java.lang.String input,
int nReportLevel,
java.lang.Appendable output,
java.lang.Appendable errOut)
executeCmdLine in interface MainCmd_ifcprocessBuilder - The ProcessBuilder. There may be assigned environment variables and a current directory.cmd - The cmd and arguments. If it is null, the command assigened to the processBuilder is used.
The command can contain arguments separated with spaces (usual for command lines) or white spaces.
The method #splitArgs(String) is used.input - Any pipe-input. It may be null.nReportLevel - The report level which is used for output.
If it is 0, then the output isn't writtenoutput - The output pipe.sAnswer - The error pipe. If it is null, then errors are written in the output pipe.public int executeCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String[] cmd,
java.lang.String input,
int nReportLevel,
java.lang.Appendable output,
java.lang.Appendable errOut)
executeCmdLine in interface MainCmd_ifcprocessBuilder - The ProcessBuilder. There may be assigned environment variables and a current directory.cmd - The cmd and arguments. If it is null, the command assigend to the processBuilder is used.input - Any pipe-input. It may be null.nReportLevel - The report level which is used for output.
If it is 0, then the output isn't writtenoutput - The output pipe.sAnswer - The error pipe. If it is null, then errors are written in the output pipe.public int startCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String cmd)
startCmdLine in interface MainCmd_ifccmd - The command. Some arguments are possible, they should be separated by space.processBuilder - The processBuilder.public int startCmdLine(java.lang.ProcessBuilder processBuilder,
java.lang.String[] cmd)
startCmdLine in interface MainCmd_ifccmd - The command and some arguments.processBuilder - The processBuilder.public int switchToWindowOrStartCmdline(java.lang.ProcessBuilder processBuilder,
java.lang.String sCmd,
java.lang.String sWindowTitle)
MainCmd_ifcswitchToWindowOrStartCmdline in interface MainCmd_ifcprocessBuilder - The processBuilder.sWindowTitle - The title or the start of the window if the process is running already.
Note: The title is depending from the application.
Sometimes the title starts with the associated file, forex calling windows-notepad.public final void writeInfo(java.lang.CharSequence sInfo)
writeInfo in interface LogMessagesInfo - String to be written.public final void writeInfoln(java.lang.CharSequence sInfo)
writeInfoln in interface LogMessagesInfo - String to be written.public final void writeWarning(java.lang.CharSequence sInfo)
writeWarning in interface LogMessagesInfo - The error text, it should be without such hot spot words line "!!!WARNING!!!",
because the distinction in display should be done by the implementation of this method.
A good sample is writeErrorln("file is empty: " + sFileName);public final void writeError(java.lang.CharSequence sInfo)
writeError in interface LogMessagesInfo - The error text, it should be without such hot spot words line "!!!ERROR!!!",
because the distinction in display should be done by the implementation of this method.
A good sample is writeErrorln("cannot create file: " + sFileName);public final void writef(java.lang.String msg,
java.lang.Object... args)
LogMessagewritef in interface LogMessagemsg - should begin with "\n", can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public final void writeInfo(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteInfo in interface LogMessagemsg - should begin with "\n", can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public final void writeInfoAdd(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteInfoAdd in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public final void writeWarning(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteWarning in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public final void writeWarningAdd(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteWarningAdd in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public final void writeError(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteError in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public final void writeErrorAdd(java.lang.String msg,
java.lang.Object... args)
LogMessagewriteErrorAdd in interface LogMessagemsg - can be contain format placeholder, String.format(String, Object...) is usedargs - The args for the placeholder.public final void writeError(java.lang.String sInfo,
java.lang.Throwable exception)
writeError in interface LogMessageexception - The catched Exception. The getMessage()-part of the exception is written after sError.
The stacktrace of the exception is written to report.public void writeStackTrace(java.lang.Exception exception)
writeStackTrace in interface MainCmdLogging_ifcpublic void writeDirectly(java.lang.CharSequence sInfo,
short kind)
#out or #err. That channels are gotten from
System.out and System.err on construction of this class. Usual that channels are non-overriden, so that it is
the console output.
System.setErr(PrintStream) or System.setOut(PrintStream) was invoked,
this routine is not influenced.
setOutputChannels(Appendable, Appendable).sInfo - The String to writekind - Combination of bits mWarning_writeInfoDirectly, mError_writeInfoDirectly
or mNewln_writeInfoDirectly.public void writeErrorDirectly(java.lang.CharSequence sInfo,
java.lang.Throwable exception)
sInfo - Text to write in the new line after "EXCEPTION: ".exception - Its getMessage will be written.public void report(int nLevel,
java.lang.CharSequence ss)
report in interface LogMessagenLevel - write the report only if the demand level is greater or equal. Use LogMessage.error
etc.ss - String to write.public void reportln(int nLevel,
int nLeftMargin,
java.lang.CharSequence ss)
reportln in interface LogMessagenLevel - write the report only if the demand level is greater or equal.nLeftMargin - determins a left margin. First a new line is outputted, followed by '*' and spaces.ss - String to write.public void reportln(int nLevel,
java.lang.CharSequence ss)
LogMessagereportln in interface LogMessagenLevel - write the report only if the demand level is greater or equal.ss - String to write.public void report(java.lang.CharSequence sInfo,
java.lang.Throwable exception)
report in interface LogMessagesInfo - Text to write in the new line after "EXCEPTION: ".exception - Exception info to writeprivate void report(java.lang.CharSequence sInfo,
java.lang.Throwable exception,
boolean bWrittenOnDisplay)
sInfo - Text to write in the new line after "EXCEPTION: "
and before the exception.getMessage is written.exception - Exception info to writebWrittenOnDisplay - true, than the writing to display is always done.public int getReportLevel()
getReportLevel in interface LogMessagepublic int setReportLevel(int newLevel)
setReportLevel in interface LogMessagenewLevel - The level to be set, use one of the defines MainCmdLogging_ifc.info to MainCmdLogging_ifc.fineDebugpublic void flushReport()
LogMessageflushReport in interface LogMessagepublic void setReportLevelToIdent(int nLevel,
int nLevelActive)
LogMessagesetReportLevelToIdent in interface LogMessagenLevelActive - Ones of the known priotity levels Report.error to Report.fineDebug.
class MyModule
{ /**Define module-specific numbers to identify a level.
* The numbers should be define regarding a band of numbers in the application.
* /
static final int myReportLevel1 = 3500, myReportLevel2=3501;
void init()
{ setLevelActive(myReportLevel1, Report.info); //This reports should be outputted always
setLevelActive(myReportLevel2, Report.debug); //This reports are debug infos.
}
void processAnything()
{ report.reportln( myReportLevel1, "InfoText"); //It depends on the report level settings
report.reportln( myReportLevel2, "DebugText");//whether it is outputed or not.
}
public int getReportLevelFromIdent(int ident)
LogMessagegetReportLevelFromIdent in interface LogMessageident - The identifier.public java.lang.String getReportFileName()
MainCmd_ifcgetReportFileName in interface MainCmd_ifcprotected void addMsgConfig(java.lang.String sFileName)
public boolean sendMsg(int identNumber,
java.lang.CharSequence text,
java.lang.Object... args)
#sendMsg(int, OS_TimeStamp, String, Object...).sendMsg in interface LogMessageidentNumber - of the message. If it is negative, it is the same message as positive number,
but with information 'going state', where the positive number is 'coming state'.text - The text representation of the message, format string, see java.lang.String.format(..).args - 0, 1 or more arguments of any type.
The interpretation of the arguments is controlled by param text.public boolean sendMsgTime(int identNumber,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
java.lang.Object... args)
sendMsgTime in interface LogMessageidentNumber - of the message. If it is negative, it is the same message as positive number,
but with information 'going state', where the positive number is 'coming state'.creationTime - absolute time stamp. @Java2C=perValue.text - The text representation of the message, format string, see java.lang.String.format(..).args - 0, 1 or more arguments of any type.
The interpretation of the arguments is controlled by param text.public boolean sendMsgVaList(int identNumber,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
Va_list args)
#sendMsg(int, OS_TimeStamp, String, Object...), but the parameter args is varied:sendMsgVaList in interface LogMessageidentNumber - creationTime - text - typeArgs - Type chars, ZCBSIJFD for boolean, char, byte, short, int, long, float double.args - Reference to a buffer which contains the values for a variable argument list.
vprintf(buffer, text, args).
The referenced instance shouldn't accepted as persistent outside processing time
of the called routine. Therefore stack content is able to provide.
public java.lang.Appendable append(java.lang.CharSequence csq)
throws java.io.IOException
append in interface java.lang.Appendablejava.io.IOExceptionpublic java.lang.Appendable append(java.lang.CharSequence csq,
int start,
int end)
throws java.io.IOException
append in interface java.lang.Appendablejava.io.IOExceptionpublic java.lang.Appendable append(char c)
throws java.io.IOException
append in interface java.lang.Appendablejava.io.IOExceptionpublic void close()
close mean.
If the device is a log file writer it should be clearly.
close may mean, the processing of messages is finite temporary.
An open occurs automatically, if a new message is dispatched.close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in interface LogMessagepublic void flush()
flush mean.
If the device is a log file writer it should be clearly.
flush may mean, the processing of messages is ready to transmit yet.flush in interface LogMessagepublic boolean isOnline()
isOnline in interface LogMessagefinal void sendMsgTimeToAppendableDst(java.lang.Appendable dst,
int identNumber,
int reportLevel,
OS_TimeStamp creationTime,
java.lang.CharSequence text,
java.lang.Object... args)
public LogMessage getLogMessageOutputConsole()
ReportgetLogMessageOutputConsole in interface Reportpublic LogMessage getLogMessageErrorConsole()
ReportgetLogMessageErrorConsole in interface Reportpublic LogMessage getLogMessageOutputFile()
ReportgetLogMessageOutputFile in interface Reportpublic static MainCmdLogging_ifc getLogging_ifc()
MainCmdLoggingStream
instance if this class is not instanciated.public static void XXXassertion(boolean condition)
condition -