https://github.com/silentsoft/arguments-parser
Java command line arguments parser. Do not parsing main(String[] args) anymore !
https://github.com/silentsoft/arguments-parser
arguments command-line parser
Last synced: 10 months ago
JSON representation
Java command line arguments parser. Do not parsing main(String[] args) anymore !
- Host: GitHub
- URL: https://github.com/silentsoft/arguments-parser
- Owner: silentsoft
- License: apache-2.0
- Created: 2020-07-08T14:00:03.000Z (over 5 years ago)
- Default Branch: dev
- Last Pushed: 2023-08-23T02:23:09.000Z (over 2 years ago)
- Last Synced: 2024-05-02T02:43:50.970Z (almost 2 years ago)
- Topics: arguments, command-line, parser
- Language: Java
- Homepage:
- Size: 59.6 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Arguments Parser
[](https://search.maven.org/artifact/org.silentsoft/arguments-parser)
[](https://app.travis-ci.com/silentsoft/arguments-parser)
[](https://sonarcloud.io/dashboard?id=silentsoft_arguments-parser)
[](https://sonarcloud.io/dashboard?id=silentsoft_arguments-parser)
[](https://hits.sh/github.com/silentsoft/arguments-parser/)
> Do not parsing main(args) anymore !
`Arguments Parser` is a simple java library to parse command line arguments.
## Supported Formats
* -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
## Maven Central
```xml
org.silentsoft
arguments-parser
2.0.1
```
## Usage
```java
public static void main(String[] args) throws Exception {
Arguments arguments = Arguments.parser(args).parse();
}
```
## Advanced Topics
### Arguments Helper Usage
If the `args` contains one of the following help commands then `ArgumentsHelper.help(Arguments)` will be invoked.
* -help
* --help
* -?
* --?
```java
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();
}
```
### Arguments Validator Usage
```java
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();
}
```
### Parsing Options with dash prefix
* LEAVE_DASH_PREFIX `(default)`
* CASE_SENSITIVE_SINGLE_DASH `(default)`
* CASE_INSENSITIVE_SINGLE_DASH
* CASE_SENSITIVE_DOUBLE_DASH
* CASE_INSENSITIVE_DOUBLE_DASH `(default)`
### Parsing Options without dash prefix
* REMOVE_DASH_PREFIX
* CASE_SENSITIVE
* CASE_INSENSITIVE
### Usage
```java
public static void main(String[] args) throws Exception {
Arguments arguments = Arguments.parser(args, ParsingOptions...).parse();
}
```
## Packaging
```
$ mvn clean package
```
## Contributing
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](https://github.com/silentsoft/arguments-parser/blob/master/CODE_OF_CONDUCT.md), please follow it in all your interactions with the project.
## License
Please refer to [LICENSE](https://github.com/silentsoft/arguments-parser/blob/master/LICENSE.txt).