Skip to content

dr1fter/cli-parsec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CLI-Parsec - a declarative CLI parser framework for Java

WHAT IS IT?

CLI-Parsec is a Java library that aims to ease the task of implementing command line interfaces. It uses a declarative approach based on Java annotations. The supported command line style adheres to the recommendations of POSIX (with some GNU extensions, such as long options). CLI-Parsec was inspired by both the Java 'jCommander'and the C# 'Command Line Parser Library'.

WHY USE IT?

The topmost design goal of CLI-Parsec is ease-of-use in combination with a consequent declaration-only approach. It will help you implement command line interfaces with a minimum amount of coding (as simple as creating a POJO and annotating its fields). CLI-Parsec is especially targeted towards complex command line interfaces (arbitrarily nested sub-commands with individual options).

HOW TO USE IT?

After its release to maven central, use the following dependency to reference the library:

<dependency>
  <groupId>de.dr1fter</groupId>
  <artifactId>de.dr1fter.cli-parsec</artifactId>
  <version>0.2.1</version>
</dependency>

Declare a type and annotate its fields in order to define the command line interface:

class MyOptions
{
  @Option(shortOption="x")
  boolean optionx;

  @Option
  String username;
}

Parse command line arguments:

MyOptions opts = new MyOptions();
CliParser.create().parse(opts, "-x", "--username", "myName");
//the fields of 'opts' are now initialised according to the command line args

About

annotation-based CLI parser framework for Java (1.6+)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages