Do not parsing main(args) anymore !
Arguments Parser
is a simple java library to parse command line arguments.
- -a -b
- -key1=value1 -key2=value2
- -key1 value1 -key2 value2
- -key1=value1 value2 -key2=value3 value4
- -key1 value1 value2 -key2 value3 value4
- --a --b
- --key1=value1 --key2=value2
- --key1 value1 --key2 value2
- --key1=value1 value2 --key2=value3 value4
- --key1 value1 value2 --key2 value3 value4
<dependency>
<groupId>org.silentsoft</groupId>
<artifactId>arguments-parser</artifactId>
<version>2.0.1</version>
</dependency>
public static void main(String[] args) throws Exception {
Arguments arguments = Arguments.parser(args).parse();
}
If the args
contains one of the following help commands then ArgumentsHelper.help(Arguments)
will be invoked.
- -help
- --help
- -?
- --?
public static void main(String[] args) throws Exception {
Arguments arguments = parseArguments(args);
}
private static Arguments parseArguments(String[] args) throws InvalidArgumentsException {
return Arguments.parser(args).help(arguments -> {
StringBuilder builder = new StringBuilder();
builder.append("Usage: java -jar application.jar [arguments]\n");
builder.append("\n");
builder.append("Common arguments:\n");
// ...
System.out.println(builder.toString());
System.exit(0);
}).parse();
}
public static void main(String[] args) throws Exception {
Arguments arguments = parseArguments(args);
}
private static Arguments parseArguments(String[] args) throws InvalidArgumentsException {
return Arguments.parser(args).validate(arguments -> {
if (arguments.containsKey("-a") && arguments.containsKey("-b")) {
throw new InvalidArgumentsException("'-a' and '-b' cannot be exists together.");
}
return true;
}).parse();
}
- LEAVE_DASH_PREFIX
(default)
- CASE_SENSITIVE_SINGLE_DASH
(default)
- CASE_INSENSITIVE_SINGLE_DASH
- CASE_SENSITIVE_DOUBLE_DASH
- CASE_INSENSITIVE_DOUBLE_DASH
(default)
- REMOVE_DASH_PREFIX
- CASE_SENSITIVE
- CASE_INSENSITIVE
public static void main(String[] args) throws Exception {
Arguments arguments = Arguments.parser(args, ParsingOptions...).parse();
}
$ mvn clean package
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please note we have a CODE_OF_CONDUCT, please follow it in all your interactions with the project.
Please refer to LICENSE.