jeneric-cmdline

Java library for adding command-line handling to arbitrary classes, via introspection.

License

License

GroupId

GroupId

com.github.waikato
ArtifactId

ArtifactId

jeneric-cmdline
Last Version

Last Version

0.0.6
Release Date

Release Date

Type

Type

jar
Description

Description

jeneric-cmdline
Java library for adding command-line handling to arbitrary classes, via introspection.
Project Organization

Project Organization

University of Waikato, Hamilton, NZ
Source Code Management

Source Code Management

https://github.com/waikato/jeneric-cmdline

Download jeneric-cmdline

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
com.github.waikato : jclasslocator jar 0.0.7

Project Modules

There are no modules declared in this project.

jeneric-commandline

Java library for adding command-line handling to arbitrary classes, via introspection.

If a public get/set method exists for a property, then this will automatically get exposed via a command-line option.

Types supported by handlers (nz.ac.waikato.cms.jenericcmdline.handlers.Handler):

  • boolean
  • byte
  • short
  • int
  • long
  • float
  • double
  • string
  • enum

Traversal of nested objects that aren't covered by one of the above handlers, is possible as well and depends on the traversal policy (nz.ac.waikato.cms.jenericcmdline.traversal.Traverser). Currently available:

  • All -- traverse all objects
  • SpecificClasses -- traverses only the specified classes

Used by ADAMS.

Example

import nz.ac.waikato.cms.jenericcmdline.DefaultProcessor;
import nz.ac.waikato.cms.jenericcmdline.traversal.All;
import nz.ac.waikato.cms.jenericcmdline.example.Simple;
import nz.ac.waikato.cms.jenericcmdline.example.Nested;

// set up simple object values
Simple simple = new Simple();
simple.setTruth(true);
simple.setEightBit((byte) 7);
simple.setSixteenBit((short) 42);
simple.setThirtyTwoBit(314);
simple.setSixtyFourBit(31415);
simple.setFloatie(0.123f);
simple.setQuadrupleHalf(123.456);
simple.setMoreThanOneTruth(new boolean[]{true, false, true});
simple.setManyInts(new int[]{1, 2, 3});
simple.setSomeDoubles(new double[]{0.1, 0.2, 0.3});
simple.setOneTwoThree(OneTwoThree.THREE);
simple.setMany(new OneTwoThree[]{OneTwoThree.ONE, OneTwoThree.TWO});

// another simple object
Simple simple2 = new Simple();
simple2.setTruth(false);
simple2.setEightBit((byte) 1);
simple2.setFloatie(1.234f);

// object with other nested, non-primitive objects
Nested nested = new Nested();
nested.setSimple(simple);
nested.setSimpleArray(new Simple[]{new Simple(), simple2});
nested.setFloating(0.456);
nested.setIntegral(1234);

// cmdline generation and parsing
DefaultProcessor processor = new DefaultProcessor();
processor.setTraverser(new All())
String cmdline;

System.out.println("\nSimple");
cmdline = processor.toCommandline(simple);
System.out.println("-initial commandline:\n" + cmdline);
Simple simpleNew = (Simple) processor.fromCommandline(cmdline);
cmdline = processor.toCommandline(simpleNew);
System.out.println("-to and from commandline:\n" + cmdline);

System.out.println("\nNested");
cmdline = processor.toCommandline(nested);
System.out.println("-initial commandline:\n" + cmdline);
Nested nestedNew = (Nested) processor.fromCommandline(cmdline);
cmdline = processor.toCommandline(nestedNew);
System.out.println("-to and from commandline:\n" + cmdline);

Maven

Add the following dependency to your pom.xml:

    <dependency>
      <groupId>com.github.waikato</groupId>
      <artifactId>jeneric-cmdline</artifactId>
      <version>0.0.6</version>
    </dependency>
com.github.waikato

Computing and Mathematical Sciences, University of Waikato

Versions

Version
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1