CLI

A lightweight Command Line Interface for Java

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

com.vtence.cli
ArtifactId

ArtifactId

cli
Last Version

Last Version

1.1
Release Date

Release Date

Type

Type

jar
Description

Description

CLI
A lightweight Command Line Interface for Java
Source Code Management

Source Code Management

https://github.com/testinfected/cli

Download cli

How to add to project

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

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Build Status Coverage Status

Getting Started

Build yourself (for latest version) using Gradle or Maven, or simply download from Maven Central:

<dependency>
      <groupId>com.vtence.cli</groupId>
      <artifactId>cli</artifactId>
      <version>1.1</version>
</dependency>

First let's define a command line:

CLI cli = new CLI() {{
    name("petstore"); version("1.0");
    description("A web application built without frameworks");

    option("-e", "--environment ENV", "Environment to use for configuration (default: development)").defaultingTo("development");
    option("-h", "--host HOST", "Host address to bind to (default: 0.0.0.0)").defaultingTo("0.0.0.0");
    option("-p", "--port PORT", "Port to listen on (default: 8080)").ofType(int.class).defaultingTo(8080);
    option("--timeout SECONDS", "Session timeout in seconds (default: 15 min)").ofType(int.class).defaultingTo(900);
    flag("-q", "--quiet", "Operate quietly");
    flag("-h", "--help", "Print this help message");

    operand("webroot", "Location of the web application").ofType(File.class);
    
    epilog("use --help to show this help message");
}};

Now assuming program is started with:

-p 8088 -e production --timeout 9000 /path/to/webapp/root

Here's how we would parse the arguments:

cli.parse(args); // Typical program args

String env = cli.get("-e");
String host = cli.get("-h");
int port = cli.get("-p");
int timeout = cli.get("--timeout");
boolean quiet = cli.has("-q");

File webroot = cli.get("webroot");

Want to know more?

Checkout out usage examples

Versions

Version
1.1