Package net.kafujo.cli
Class CliApp
- java.lang.Object
-
- net.kafujo.cli.CliApp
-
- All Implemented Interfaces:
TypedReader
- Direct Known Subclasses:
CliAppKafujo
public class CliApp extends Object implements TypedReader
Makes it easier to create Apache Commons CLI apps. Offers three useful standard options.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.commons.cli.CommandLinecommandLineprotected PrintStreamerrprotected PrintStreamout
-
Constructor Summary
Constructors Constructor Description CliApp()Default ctor with default values: '?' help (showing help when there are no args) 'S' stats 'W' wait (waiting forever)CliApp(String standardHelpOpt, boolean showHelpOnNoArgs, String standardStatsOpt, String standardWaitOpt, Duration standardWaitDuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidadd(RunnableResult<Boolean> code, org.apache.commons.cli.Option option)protected voidadd(org.apache.commons.cli.Option option)protected voidaddArgOption(RunnableResult<Boolean> code, String opt, String description)protected voidaddNoArgOption(RunnableResult<Boolean> code, String opt, String description)protected voidaddOptionalArgOption(RunnableResult<Boolean> code, String opt, String description)Adds anOptionwith ONE optional argument.protected voidaddStandardHelpOption()Adds an option wiprotected voidaddStandardOptions()Adds all default options.protected voidaddStandardStatsOption()protected voidaddStandardWaitOption()protected booleanconfirmNextStep(String message)Prints message and ask for confirmation.protected booleanconfirmOverwrite(Path file)Checks if file exists and asks, if it can be overwritten.protected booleanhelp()The default help.booleanisAvailable(CharSequence key)StringreadString(CharSequence key)protected voidrun(String[] args)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.kafujo.config.TypedReader
readBigDecimal, readBigDecimalFbk, readBigInteger, readBigIntegerFbk, readBoolean, readBooleanFbk, readDouble, readDoubleFbk, readDuration, readDurationFbk, readDurationOfMillis, readDurationOfMillisFbk, readDurationOfMillisFbk, readDurationOfSeconds, readDurationOfSecondsFbk, readDurationOfSecondsFbk, readEmailAddress, readEmailAddressFbk, readEmailAddressFbk, readFileToBytes, readFileToLines, readFileToString, readFloat, readFloatFbk, readHost, readHostFbk, readHostFbk, readHostname, readHostnameFbk, readHostnameFbk, readHostWithPort, readHostWithPortFbk, readHostWithPortFbk, readInt, readIntFbk, readLong, readLongFbk, readPath, readPathFbk, readPathFbk, readPort, readPortFbk, readShort, readShortFbk, readStringFbk, readStringFbk, readUrl, readUrlFbk
-
-
-
-
Field Detail
-
out
protected final PrintStream out
-
err
protected final PrintStream err
-
commandLine
protected org.apache.commons.cli.CommandLine commandLine
-
-
Method Detail
-
addStandardOptions
protected final void addStandardOptions()
Adds all default options.
-
addStandardHelpOption
protected void addStandardHelpOption()
Adds an option wi
-
addStandardStatsOption
protected void addStandardStatsOption()
-
addStandardWaitOption
protected void addStandardWaitOption()
-
help
protected boolean help()
The default help. You can overwrite this in the actual class to show a specialized help screen.- Returns:
- always false to signal the end of the program
-
add
protected void add(org.apache.commons.cli.Option option)
-
add
protected void add(RunnableResult<Boolean> code, org.apache.commons.cli.Option option)
-
addNoArgOption
protected void addNoArgOption(RunnableResult<Boolean> code, String opt, String description)
-
addArgOption
protected void addArgOption(RunnableResult<Boolean> code, String opt, String description)
-
addOptionalArgOption
protected void addOptionalArgOption(RunnableResult<Boolean> code, String opt, String description)
Adds anOptionwith ONE optional argument.- Parameters:
code-runnablefor this option.opt- short namedescription- describes what it does
-
isAvailable
public boolean isAvailable(CharSequence key)
- Specified by:
isAvailablein interfaceTypedReader
-
readString
public String readString(CharSequence key)
- Specified by:
readStringin interfaceTypedReader
-
run
protected void run(String[] args)
-
confirmNextStep
protected boolean confirmNextStep(String message)
Prints message and ask for confirmation. User has to enter y or n.- Parameters:
message- question to be confirmed or not.- Returns:
- true, if user confirms
-
confirmOverwrite
protected boolean confirmOverwrite(Path file)
Checks if file exists and asks, if it can be overwritten.- Parameters:
file- file to be checked- Returns:
- false if file exists and user doen't confirm overwrite. Else true.
- Throws:
RequirementException- if file exists but is directory
-
-