Skip to content

silentsoft/arguments-parser

dev
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Arguments Parser

Maven Central Build Status Quality Gate Status Coverage Hits

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

<dependency>
    <groupId>org.silentsoft</groupId>
    <artifactId>arguments-parser</artifactId>
    <version>1.1.0</version>
</dependency>

Usage

public static void main(String[] args) throws Exception {
    Arguments arguments = ArgumentsParser.parse(args);
}

Advanced Topics

Arguments Validator Usage

public static void main(String[] args) throws Exception {
    ArgumentsValidator validator = (arguments) -> {
        if (arguments.containsKey("-a") && arguments.containsKey("-b")) {
            throw new InvalidArgumentsException("'-a' and '-b' cannot be exists together.");
        }
        
        return true;
    };
    
    Arguments arguments = ArgumentsParser.parse(args, validator);
}

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

public static void main(String[] args) throws Exception {
    Arguments arguments = ArgumentsParser.parse(args).with(ParsingOptions...);
}

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, please follow it in all your interactions with the project.

License

Please refer to LICENSE.

About

Java command line arguments parser. Do not parsing main(String[] args) anymore !

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages