Skip to content

A collection of useful tools if you want to make a command line interface of some sorts.

License

Notifications You must be signed in to change notification settings

UnterrainerInformatik/java-cli-utils

Repository files navigation

GitHub forks GitHub stars GitHub repo size GitHub issues

license Travis-build Maven Central Twitter Follow

java-cli-utils

A collection of useful tools if you want to make a command line interface of some sorts.

Console-Progressbar

The console-progressbar is designed to show progress when writing long-running console-applications.
It was designed to be used with consoles that support control-characters (like cmd) or that don't (Eclipse console implementation before Mars (4.5)).

It comes with three flavors:

SimpleInsertBar

Works with non-control-character enabled consoles. Uses a completely new line for adding progress-characters instead.

prefix: [>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]
         ##################################################

ProgressBar

Your ASCII-progressbar. Uses the same line, requiring ASCII escape characters.

prefix: [########------------------------------------------]

PercentGauge

Displays the percentage. Needs ASCII escape characters as well.

prefix: [ 72%]

You may extend the visual representations by implementing new graphical variants.

Example

ConsoleProgressBar bar = ConsoleProgressBar.builder().maxValue((double)list.size()).
    controlCharacterSupport(!isForFileOut).build();

int count = 0;
for (String s : list) {
    doSomething(s);

    bar.updateValue(++count).redraw(System.out);
}

bar.complete().redraw(System.out);
System.out.println("\n");

CliParser

This is a fluent wrapper over the Apache Commons CLI library.

Usage

Cli cli = CliParser
	.cliFor(args, "ServerBrowser", "a small tool to help validate some things")
    .addArg(Arg.String("server").shortName("s")
	.description("the server instance to connect to (http://<ip>.<port>)")
	.defaultValue(SERVER).optional())
	.addArg(Arg.String("user").shortName("u").description("the user to use when connecting to the server")
	.defaultValue(USER).optional())
	.addArg(Arg.String("password").shortName("p")
	.description("the password used when connecting to the server").defaultValue(PASSWORD)
	.optional())
	.addFlag(Flag.builder("list").shortName("l")
	.description("browses and lists all REST-API methods of this server instance"))
	.addMinRequired(1, "list").create();
if (cli.isHelpSet()) {
	System.exit(0);
}
String endpointUrl = cli.getArgValue("server");
String user = cli.getArgValue("user");
String password = cli.getArgValue("password");

if (cli.isFlagSet("list")) {
    // do something...
}

About

A collection of useful tools if you want to make a command line interface of some sorts.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages