Skip to content

valery1707/jcommander-ext

Repository files navigation

Maven Central License

Build Status Coverage Status CodeBeat badge

Waffle.io - Columns and their card count

JCommander is very good command line parsing framework for Java.

"Because life is too short to parse command line parameters" © Cédric Beust

JCommander not only can parse program arguments, it also has an extension point for validation of argument values. At the same time JCommander does not contain (at least in version 1.64) any validators.

This library is designed to correct this omission.

Validators

Some validators is ready to use, but I can't guess all useful cases and many validators designed to be useful after simple extension without any logic implementation.

Example: if you need validate argument value to be within some borders, you need only:

  1. extend class InRange
  2. create default constructor
  3. pass in super constructor required borders
  4. use your class in @Parameter#validateValueWith

Validators list:

  1. Common
    1. Range: InRange, NotInRange
    2. Collection: InCollection
  2. Number
    1. Equal: EqualTo, NotEqualTo
    2. Greater: GreaterThan, GreaterThanOrEqualTo
    3. Less: LessThan, LessThanOrEqualTo
    4. Zero-compare: EqualToZero, NotEqualToZero, GreaterThanZero, GreaterThanOrEqualToZero, LessThanZero, LessThanOrEqualToZero
  3. String
    1. Simple: NotBlank, NotEmpty
    2. Pattern based: PatternContains, PatternNotContains, PatternMatched, PatternNotMatched
  4. IO
    1. Base: Exists, NotExists
    2. File: ExistsFile, ExistsFileReadable, ExistsFileWritable, ExistsFileExecutable
    3. Directory: ExistsDirectory, ExistsDirectoryReadable, ExistsDirectoryWritable, ExistsDirectoryExecutable
  5. NIO
    1. Base: Exists, NotExists
    2. File: ExistsFile, ExistsFileReadable, ExistsFileWritable, ExistsFileExecutable
    3. Directory: ExistsDirectory, ExistsDirectoryReadable, ExistsDirectoryWritable, ExistsDirectoryExecutable
    4. Link: ExistsLink, ExistsLinkReadable, ExistsLinkWritable, ExistsLinkExecutable

Build

Build with code coverage report: clean package jacoco:report