- java.lang.Object
-
- io.github.mmm.cli.CliMain
-
- Direct Known Subclasses:
NlsMain
public abstract class CliMain extends Object
This is the abstract base class for a main-program.
You simply need to extend this class and implementrun(CliArgs)
. For advanced CLIs please extendio.github.mmm.nls.cli.NlsMain
frommmm-nls-cli
.- Since:
- 1.0.0
-
-
Field Summary
Fields Modifier and Type Field Description protected CliConsole
c
-
Constructor Summary
Constructors Constructor Description CliMain()
The constructor.CliMain(CliConsole console)
The constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description CliConsole
console()
protected void
error(CliArgument argument)
protected int
error(Throwable error)
protected String
getVersion()
abstract int
run(CliArgs args)
Has to be implemented to handle that givenCliArgs
and do the program logic.int
run(String... args)
protected void
runAndExit(String... args)
This method delegates torun(String...)
and then callsSystem.exit(int)
with the returned exit code.
-
-
-
Field Detail
-
c
protected final CliConsole c
- See Also:
console()
-
-
Constructor Detail
-
CliMain
public CliMain()
The constructor.
-
CliMain
public CliMain(CliConsole console)
The constructor.- Parameters:
console
- theCliConsole
to use.
-
-
Method Detail
-
console
public CliConsole console()
- Returns:
- the
CliConsole
.
-
error
protected void error(CliArgument argument)
- Parameters:
argument
- theCliArgument
that was unexpected at this place.
-
error
protected int error(Throwable error)
-
getVersion
protected String getVersion()
- Returns:
- the version of this program.
-
run
public abstract int run(CliArgs args)
Has to be implemented to handle that givenCliArgs
and do the program logic.
-
run
public int run(String... args)
This method parses the givenargs
asCliArgs
and delegates torun(CliArgs)
. Additionally it will catch and handle any kind oferrors
.- Parameters:
args
- are the command-line arguments.- Returns:
- the
exit code
.
-
runAndExit
protected void runAndExit(String... args)
This method delegates torun(String...)
and then callsSystem.exit(int)
with the returned exit code. Typically you only need to call this method from your actualmain
method.- Parameters:
args
- are the command-line arguments.
-
-