Skip to content
/ jParser Public

A java module to easily parse console arguments in a similar style as getOpt() in C

Notifications You must be signed in to change notification settings

divios/jParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jParser

A java module to easily parse console arguments in a similar style as getOpt() in C

Usage

jParser provides a very simple console Argument parser abstraction. The main idea is to specify a filter, which is a string with all the expected parameters. For example, "apd" expects parameters a, p and d. Also if a parameter is followed by ":", it means that the parameter requires an Argument.

It also comes with various methods to assert the result of the arguments.

Map<Character, Argument> argsMap = Parser.builder()
      .filter("p:s:d")
      .assertType('p', argType.INTEGER, "parameter p needs to be an integer")
      .assertDefault('s', "127.0.0.1")
      .parse(args)
      .getAsMap();
      
String host = argsMap.get('s').getAsString();
int port = argsMap.get('p').getAsInt();
boolean debug = argsMap.get('d').getAsBoolean();

Instalation

To get the jar, either download it from the releases tab either here on GitHub or build it locally.

With Jitpack:

Gradle:

repositories {
        maven { url 'https://jitpack.io' }
}
dependencies {
        compileOnly 'com.github.divios:jparser:Tag'
}

Maven:

<repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
</repository>
<dependency>
        <groupId>com.github.divios</groupId>
        <artifactId>jparser</artifactId>
        <version>Tag</version>
        <scope>provided</scope>
</dependency>

Replace Tag with a release tag for jParser. Example: 1.0. You can also use master as the tag to get the latest version, though you will have to clear your maven caches in order to update it.

Build locally:

For Windows, use Git Bash. For Linux or OSX, just ensure you have Git installed. Navigate to the directory where you want to clone the repository, and run:

git clone https://github.com/divios/jparser
cd jParser
./gradlew jar

After running these commands, the jar will be at build/libs/jParser.jar. You may also need to add the jar to your classpath. After that, you should be good to go!

About

A java module to easily parse console arguments in a similar style as getOpt() in C

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages