java.lang.Object
io.github.mmm.cli.CliMain
This is the abstract base class for a main-program.
You simply need to extend this class and implement
You simply need to extend this class and implement
run(CliArgs). For advanced CLIs please extend
io.github.mmm.nls.cli.NlsMain from mmm-nls-cli.- Since:
- 1.0.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAddstheCliCommands for this program.console()protected voiderror(CliArgument argument) protected intprotected CliAddCommandgroup()protected CliAddCommandprotected booleanfinal intHas to be implemented to handle that givenCliArgsand do the program logic.intprotected voidrunAndExit(String... args) This method delegates torun(String...)and then callsSystem.exit(int)with the returned exit code.
-
Field Details
-
console
- See Also:
-
-
Constructor Details
-
CliMain
public CliMain()The constructor. -
CliMain
The constructor.- Parameters:
console- theCliConsoleto use.
-
-
Method Details
-
addCommands
protected void addCommands()AddstheCliCommands for this program. -
getContainer
- Returns:
- the
CliContainerwith the groups, commands and their properties.
-
console
- Returns:
- the
CliConsole.
-
error
- Parameters:
argument- theCliArgumentthat was unexpected at this place.
-
error
-
group
- Returns:
- the root group where
CliCommands can beadded.
-
group
- Parameters:
name- thegroup name.- Returns:
- the group with the given
group namewhereCliCommands can beadded.
-
isTolerateDuplicateOptions
protected boolean isTolerateDuplicateOptions()Typically a program shall provide multiple values for aCliOptionby providing them as multipleCliValues after theCliOption(e.g. "--keys foo bar some"). However, some programs like to repeat the sameCliOptionfor that purpose (e.g. "--key foo --key bar --key some"). In case this shall cause an error you can override this method and returnfalse.- Returns:
trueto tolerate duplicate occurrences of the sameCliOption,falseotherwise (default).
-
getProgramName
- Returns:
- the name of this program.
-
getVersion
- Returns:
- the version of this program.
-
run
Has to be implemented to handle that givenCliArgsand do the program logic. -
run
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
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.
-