CLI Arguments module API tests

Tests on the API of CLI Arguments module.

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.zkejid.constructor
ArtifactId

ArtifactId

cli-arguments-apitest
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

CLI Arguments module API tests
Tests on the API of CLI Arguments module.
Project URL

Project URL

https://github.com/zkejidsconstructor/cli-arguments/tree/master/cli-arguments-apitest

Download cli-arguments-apitest

How to add to project

<!-- https://jarcasting.com/artifacts/com.zkejid.constructor/cli-arguments-apitest/ -->
<dependency>
    <groupId>com.zkejid.constructor</groupId>
    <artifactId>cli-arguments-apitest</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.zkejid.constructor/cli-arguments-apitest/
implementation 'com.zkejid.constructor:cli-arguments-apitest:1.0.0'
// https://jarcasting.com/artifacts/com.zkejid.constructor/cli-arguments-apitest/
implementation ("com.zkejid.constructor:cli-arguments-apitest:1.0.0")
'com.zkejid.constructor:cli-arguments-apitest:jar:1.0.0'
<dependency org="com.zkejid.constructor" name="cli-arguments-apitest" rev="1.0.0">
  <artifact name="cli-arguments-apitest" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.zkejid.constructor', module='cli-arguments-apitest', version='1.0.0')
)
libraryDependencies += "com.zkejid.constructor" % "cli-arguments-apitest" % "1.0.0"
[com.zkejid.constructor/cli-arguments-apitest "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.zkejid.constructor : cli-arguments-api jar 1.0.0
org.junit.jupiter : junit-jupiter jar 5.6.2

Project Modules

There are no modules declared in this project.

Build Status

CLI Arguments module

Constructor part for handling command line arguments.

Usage

Command line syntax

You can register two types of arguments: flags and properties. Flags are single letter arguments which represent boolean value. If given flag exists in an argument line, then it has value of true. If it does not exist, then it has value of false. Flags can be merged in one line argument. Here is the call to ls utility with two flags - -a and -l - merged together:

ls -al

Properties are name-value pairs, that user can specify in an argument line:

ls --tabsize=4

Command line can contain more arguments, than you registered. Parser would leave these arguments unparsed. We will refer to these arguments as plain arguments. You can force parser to treat the rest of command line as plain arguments if place -- argument. All arguments to the right from this argument wold be plain.

API

To use the API you should request ArgumentsFactory.class interface in your ConstructorPart implementation:

  @Override
  public Set<Class<?>> getInterfacesNecessary() {
    return Set.of(ArgumentsFactory.class);
  }

ArgumentsFactory allows you to create an instance of the parser:

final ArgumentsParser parser = argumentsFactory.createParser();

Parser holds the configuration of arguments given instance of parser could parse. You can create as many instances of parser as you wish and configure them separately.

You can create a flag with expression:

Argument all = parser.addFlag("a", "all");

You can create a property with expression:

Argument tabSize = parser.addProperty("T", "tabsize");

The Argument object serves as key for retrieval of value:

ParseResult parseResult = parser.parse(strings);
final StringValue allValue = parseResult.getArgumentsParsed().get(all);
if (allValue.getInputValueType() == InputValueType.SPECIFIED) {
  // handle --all 
}

Example

You can find an example of application built around the module in cli-arguemnts-helloworld artifact.

Constructor Module

CliArguments is the module of Constructor Framework. You can simply place artifacts of this module on the path of application to use its API.

Tests

Module API has set of tests. You can use cli-arguments-apitest artifact to test your own implementation of API. Artifact contains set of *CheckList files. These files are abstract JUnit5 test classes. You should extend the class ans provide your implementation through the abstract method.

Versioning

Artifact versions of the CliArguments Module follow the Semantic Versioning 2.0.0 specification.

License

The module is provided under MIT License Copyright (c) 2020 Zkejid.

Versions

Version
1.0.0