Menu

Overview

Ray

CmdConfig - a command-line argument parsing library

CmdConfig attempts to provide a lightweight approach to command line argument parsing for Java programs. Its main inspiration has been the POSIX getopt that parses the single-character standard command line options. GNU-style long options are not (yet) supported due to a personal choice: while I don't call their usefulness into question, some tools tend to abuse them. Writing a correct command with all necessary options for such tools requiring tens of long options is then a pure nuisance.
CmdConfig is supposed to support longopts in the future. For now, the library focuses on the simplest use with all the power such parsing library should provide.

POSIX getopt introduced a very simple, yet powerful way of specifying the options expected with none, optional or mandatory arguments via an option string. CmdConfig adheres to the getopt option string syntax, but takes the processing one step further. POSIX getopt's way of accessing the parsed arguments involves almost always the same recurring code consisting of a loop and a switch statement, which together gather and sort the obtained values into some type of container(s) for later queries. CmdConfig already includes this step in argument parsing, which yields a configuration instance ready to be queried about options, arguments and values obtained at the command line.

The current version of the library contains only a single class with its inner support classes and interfaces - the Config, which provides the single-character option parsing. The future versions will bring more advanced parsing and - maybe - even the longopts ;-)

Table Of Contents

  1. Config Quick Guide
  2. Config Usage Phases
  3. Config Option String
  4. Argument Parsing
  5. Access To Values
  6. Error Reporting

Related

Wiki: Access
Wiki: Error_Reporting
Wiki: Example
Wiki: Install
Wiki: Option_String
Wiki: Parsing
Wiki: Quick_Guide
Wiki: Usage_Phases