Posts

Showing posts from July, 2017

Java Command-Line Interfaces (Part 9): parse-cmd

Image
The parse-cmd library consists of a single class, ParseCmd.java , that is "a Java-class used to define and parse command-line parameters in a Java application." The library is hosted on Google Code Archive and so could go away at any time . The JAR also appears to be available on GitHub . This post covers use of parse-cmd 0.0.93 to process command line arguments in Java. The parse-cmd Requirement Wiki lists several alternatives for processing command line arguments in Java, including some which have been covered previously in this series. After listing these alternatives, it states, "Reviewing these and other entries, it was time to try another parser." The document then goes on to delineate requirements that parse-cmd seeks to satisfy. The "definition" stage of parsing command-line arguments with parse-cmd is demonstrated in the next (incomplete) code listing. [Note that the example in this post is similar to that used in the previous eight posts ...

Java Command-Line Interfaces (Part 8): Argparse4j

Image
Argparse4j is a "Java command-line argument parser library" that its main page describes as "a command line argument parser library for Java based on Python's argparse module." In this post, I will look briefly at using Argparse4j 0.7.0 to process command-line arguments similar to those parsed in the seven earlier posts in this series on command-line processing in Java. The arguments "definition" stage of command-line processing with Argparse4j can be accomplished via the ArgumentParser interface and its addArgument(String...) method. The return type of the addArgument(String...) method is an instance of the Argument interface. Implementations of that interface (usually ArgumentImpl ) provide methods for setting the characteristics of each argument. Because each of these methods returns an instance of Argument , these calls can be chained together in a highly fluent manner. This is demonstrated in the next screen snapshot. "Definition...

Java Command-Line Interfaces (Part 7): JCommander

Image
This is the seventh post in my series that briefly introduces various libraries for processing command-line arguments in Java. This post returns to coverage of an annotation-based library that seems to be one of the better known and more popular of the numerous available libraries for processing command line arguments from Java: JCommander . JCommander 's web page states, "Because life is too short to parse command line parameters" and the Overview introduces JCommander as "a very small Java framework that makes it trivial to parse command line parameters." The code examples and associated screen snapshots of the executing code in this post are based on JCommander 1.72 (June 2017). The full code for the demonstrations shown here is available on GitHub . JCommander uses annotations to implement the "definition" stage of command-line processing. This is demonstrated in the next code listing snippet. "Definition" Stage with JCommander /** ...

Java Command-Line Interfaces (Part 6): JOpt Simple

Image
The main web page for JOpt Simple calls this Java-based library "a Java library for parsing command line options, such as those you might pass to an invocation of javac ," that "attempts to honor the command line option syntaxes of POSIX getopt() and GNU getopt_long() ." This is the sixth post of my series of command-line arguments processing in Java and its focus is on JOpt Simple . Most of the libraries I've reviewed in this series of command-line processing in Java take use annotations in some way. JOpt Simple, like Apache Commons CLI , does not use annotations. JOpt Simple supports "fluent interfaces" instead. This original post's examples (code listings) and output (screen snapshots) are based on compiling and running against JOpt Simple 4.9, but they have worked similarly for me (and without code changes) when compiling them and running them with JOpt Simple 5.0.3. The next code listing demonstrates the "definition" stage of com...