Thin Wrapper to Execute methods from JDK and JVM-based libraries from the Command Line.

1
0
Java

= jcli
:nofooter:

Sugared wrappers to execute methods from JDK and JVM-based libraries from the command line.

E.g., To generate a UUID, java.util.UUID contains a method, UUID.randomUUID(). This tool helps you to execute that method by invoking jcli util -uuid.

== Motivation
The goal is to expose the wealth of utility methods available in the JVM ecosystem right at the command line.

It is also intended that this be a GraalVM-compatible project so that distributions do not require the end user to do a JVM setup with some compatible Java version.

Most methods return a single result, and so can be used in pipe operations combined with other command line utilities if needed.

== Available Commands

In order to view the latest document, you can run the help for a command or sub-command.

E.g., jcli time -help

Usage: jcli time [-hV] [-now] [-toEpochMilli]
Methods from java.time
  -h, --help        Show this help message and exit.
      -now, --now   Prints the value of Instant.now()
      -toEpochMilli, --toEpochMilli, -toEpochMillis, --toEpochMillis
                    Prints the value of Instant.now().toEpochMillis()
  -V, --version     Print version information and exit.

Here is a small sample of available options.

[cols=“1,1,1,1”]
|===
|SubCommand | Options | Description | Usage

|util
|-uuid
|Generates a UUID
|jcli util -uuid

|time
|-now
|Prints the value of current time as standard formatted date/time
|jcli time -now

|time
|-toEpochMilli
|Prints the value of current time as the number of milliseconds from the epoch of 1970-01-01T00:00:00Z.
|jcli time -toEpochMilli
|===

== Build

To build this project’s source code:

. Clone this project
. At the root of the project, execute ./gradlew clean build
. The build generates a jar at build/libs. To execute the cli app, run java -jar build/libs/jcli-0.1-all.jar -h to view the help manual.
. Or, create an alias like this. alias jcli='java -jar build/libs/jcli-0.1-all.jar'
Then run, jcli -h.

== Build Native Image

. Install and Use GraalVM
. Compile Native Image
… NativeCompile may take a few minutes (~7 minutes on My Intel / i5 / 8GB Mac)

sdk install java 17.0.8-graalce
sdk use java 17.0.8-graalce
./gradlew nativeCompile

The default output directory is build/native/nativeCompile.

Here is how you can execute the native file.

$ ./build/native/nativeCompile/jcli --help
Usage: jcli [-hvV] [COMMAND]
Sugared wrappers to execute methods of JDK and JVM-based libraries from the
command line.
  -h, --help      Show this help message and exit.
  -v, --verbose   Print welcome message.
  -V, --version   Print version information and exit.
Commands:
  time    Methods from java.time
  util    Methods from java.util
  string  Methods from java.lang.String

An example command:

$ ./build/native/nativeCompile/jcli time -fn=getEpochSecond