public class CommandLineUtils extends Object
| Constructor and Description |
|---|
CommandLineUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
checkInvalidArgs(joptsimple.OptionParser parser,
joptsimple.OptionSet options,
joptsimple.OptionSpec<?> usedOption,
joptsimple.OptionSpec<?>... invalidOptions)
Check that none of the listed options are present.
|
static void |
checkInvalidArgs(joptsimple.OptionParser parser,
joptsimple.OptionSet options,
joptsimple.OptionSpec<?> usedOption,
Set<joptsimple.OptionSpec<?>> invalidOptions)
Check that none of the listed options are present.
|
static void |
checkInvalidArgsSet(joptsimple.OptionParser parser,
joptsimple.OptionSet options,
Set<joptsimple.OptionSpec<?>> usedOptions,
Set<joptsimple.OptionSpec<?>> invalidOptions,
Optional<String> trailingAdditionalMessage)
Check that none of the listed options are present with the combination of used options.
|
static void |
checkRequiredArgs(joptsimple.OptionParser parser,
joptsimple.OptionSet options,
joptsimple.OptionSpec<?>... requiredList)
Check that all the listed options are present.
|
static boolean |
isPrintHelpNeeded(CommandDefaultOptions commandOpts)
Check if there are no options or `--help` option from command line.
|
static boolean |
isPrintVersionNeeded(CommandDefaultOptions commandOpts)
Check if there is `--version` option from command line.
|
static <T> void |
maybeMergeOptions(Properties props,
String key,
joptsimple.OptionSet options,
joptsimple.OptionSpec<T> spec)
Merge the options into
props for key key, with the following precedence, from high to low:
1) if spec is specified on options explicitly, use the value;
2) if props already has key set, keep it;
3) otherwise, use the default value of spec. |
static void |
maybePrintHelpOrVersion(CommandDefaultOptions commandOpts,
String message)
Check and print help message if there is no options or `--help` option
from command line, if `--version` is specified on the command line
print version information and exit.
|
static Properties |
parseKeyValueArgs(List<String> args)
Parse key-value pairs in the form key=value.
|
static Properties |
parseKeyValueArgs(List<String> args,
boolean acceptMissingValue)
Parse key-value pairs in the form key=value.
|
static void |
printUsageAndExit(joptsimple.OptionParser parser,
String message) |
static void |
printVersionAndExit() |
public static boolean isPrintHelpNeeded(CommandDefaultOptions commandOpts)
commandOpts - Acceptable options for a commandpublic static boolean isPrintVersionNeeded(CommandDefaultOptions commandOpts)
commandOpts - Acceptable options for a commandpublic static void maybePrintHelpOrVersion(CommandDefaultOptions commandOpts, String message)
commandOpts - Acceptable options for a commandmessage - Message to display on successful checkpublic static void checkRequiredArgs(joptsimple.OptionParser parser,
joptsimple.OptionSet options,
joptsimple.OptionSpec<?>... requiredList)
public static void checkInvalidArgs(joptsimple.OptionParser parser,
joptsimple.OptionSet options,
joptsimple.OptionSpec<?> usedOption,
joptsimple.OptionSpec<?>... invalidOptions)
public static void checkInvalidArgs(joptsimple.OptionParser parser,
joptsimple.OptionSet options,
joptsimple.OptionSpec<?> usedOption,
Set<joptsimple.OptionSpec<?>> invalidOptions)
public static void checkInvalidArgsSet(joptsimple.OptionParser parser,
joptsimple.OptionSet options,
Set<joptsimple.OptionSpec<?>> usedOptions,
Set<joptsimple.OptionSpec<?>> invalidOptions,
Optional<String> trailingAdditionalMessage)
public static void printUsageAndExit(joptsimple.OptionParser parser,
String message)
public static void printVersionAndExit()
public static Properties parseKeyValueArgs(List<String> args)
public static Properties parseKeyValueArgs(List<String> args, boolean acceptMissingValue)
public static <T> void maybeMergeOptions(Properties props, String key, joptsimple.OptionSet options, joptsimple.OptionSpec<T> spec)
props for key key, with the following precedence, from high to low:
1) if spec is specified on options explicitly, use the value;
2) if props already has key set, keep it;
3) otherwise, use the default value of spec.
A null value means to remove key from the props.