Config4CLI

Parse commandline parameters to Config object

License

License

Categories

Categories

CLI User Interface config Application Layer Libs Configuration
GroupId

GroupId

de.mukis
ArtifactId

ArtifactId

config4cli
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Config4CLI
Parse commandline parameters to Config object
Project URL

Project URL

http://muuki88.github.io/config4cli/
Source Code Management

Source Code Management

https://github.com/muuki88/config4cli

Download config4cli

How to add to project

<!-- https://jarcasting.com/artifacts/de.mukis/config4cli/ -->
<dependency>
    <groupId>de.mukis</groupId>
    <artifactId>config4cli</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/de.mukis/config4cli/
implementation 'de.mukis:config4cli:0.1.0'
// https://jarcasting.com/artifacts/de.mukis/config4cli/
implementation ("de.mukis:config4cli:0.1.0")
'de.mukis:config4cli:jar:0.1.0'
<dependency org="de.mukis" name="config4cli" rev="0.1.0">
  <artifact name="config4cli" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.mukis', module='config4cli', version='0.1.0')
)
libraryDependencies += "de.mukis" % "config4cli" % "0.1.0"
[de.mukis/config4cli "0.1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.typesafe : config jar 1.0.2
commons-cli : commons-cli jar 1.2

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

Build Status Coverage Status

Config4CLI

This little project provides a smaller converter from [http://commons.apache.org/proper/commons-cli/](Apache Commons CLI) commandline parser to the Typesafe Config.

Maven

<dependency>
  <groupId>de.mukis</groupId>
  <artifactId>config4cli</artifactId>
  <version>0.1.0</version>
</dependency>

Usage

First you generate your cli options as usual with commons-cli. For example

Options options = new Options();

Option debug = new Option("debug", "print debugging information");
Option help = new Option( "help", "print this message" );

options.addOption(debug);
options.addOption(help);

For more information look at the usage page.

Your main method could now look like this

public static void main(String[] args) {
    CommandLineParser basicParser = new BasicParser();
    CommandLine cmd = basicParser.parse(options, args);

    Config config = CommandLineConfig.fromCommandLine(cmd);
}

Conversion options

Currently theres only one conversion strategy.

non-arg options

option-name = true

Example call: -debug

single-arg options

option-name = argument

Example call: -file /absolute/path

property-arg options

option-name {
    prop1 = val1
    prop2 = val2
}

Example call: -D prop1=val1 -D prop2=val2

multi-arg options

option-name {
    argName1 = val1
    argName2 = val2
}

Example call: -position 23.6,12.4,1452,803

The options object is defined as follows. Note that the withArgName parameter must have the same structure as the actual commandline input. This includes separator and argument count.

Option position = OptionBuilder.withArgName("longitude,latitude,altitude,speed") //
         .hasArgs(4) //
         .withValueSeparator(',') //
         .withDescription("use four arguments for something") //
         .create("position");

Conversion will result in

position {
    longitude = 23.6
    latitude = 12.4
    altitude = 1452
    speed = 803
}

License

The license is Apache 2.0, see LICENSE.txt.

Links

Versions

Version
0.1.0