A collection of utility classes for my CLI projects.
Add to your pom.xml:
<repository>
<id>alka-repo</id>
<url>https://repo.alka.dev/repository/maven-public/</url>
</repository>
<dependency>
<groupId>dev.alka.javautils</groupId>
<artifactId>build-utils</artifactId>
<version>VERSION</version>
</dependency>
This allows you to generate a vertical command usage, with a any Map<String, String>
Code
import dev.alka.utils.cli.PrettyUsage;
import java.util.HashMap;
private void printUsage() {
PrettyUsage prettyUsage = new PrettyUsage();
prettyUsage.setPaddingLeft(0); // Default value
prettyUsage.setPaddingRight(3); // Default value
// By creating a map
HashMap<String, String> commands = new HashMap<>();
commands.put("-help, -h", "Get help");
commands.put("-version, -v", "Get version");
prettyUsage.importValues(commands);
// Importing manually
prettyUsage.importValue("-start", "Start server");
// Print
System.out.println("Program usage: ");
System.out.println("============== ");
for (String command : prettyUsage.getLines()) {
System.out.println(command);
}
}
Result
Program usage:
==============
-help, -h Get help
-version, -v Get version
-start Start server