- 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.NlsMainfrommmm-nls-cli.- Since:
- 1.0.0
-
-
Field Summary
Fields Modifier and Type Field Description protected CliConsolec
-
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 CliConsoleconsole()protected voiderror(CliArgument argument)protected interror(Throwable error)protected StringgetVersion()abstract intrun(CliArgs args)Has to be implemented to handle that givenCliArgsand do the program logic.intrun(String... args)protected voidrunAndExit(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- theCliConsoleto use.
-
-
Method Detail
-
console
public CliConsole console()
- Returns:
- the
CliConsole.
-
error
protected void error(CliArgument argument)
- Parameters:
argument- theCliArgumentthat 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 givenCliArgsand do the program logic.
-
run
public int run(String... args)
This method parses the givenargsasCliArgsand 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 actualmainmethod.- Parameters:
args- are the command-line arguments.
-
-