CLOPS — Command Line OPtionS

CLOPS is a Java parser and documentation generator for command line options. CLOPS guarantees that your code and your documentation are in sync.

CLOPS makes it easy to evolve the command line interface of a Java application. Once the options multiply and the syntax of the command line becomes more complicated it becomes more and more advantageous to use CLOPS.


Download CLOPS

The latest stable release
Other Download Options

Example

1. Describe the command line

src/clops/foo.clo:

NAME:: Foo
ARGS::
  SayHi
    :{"--say-hi", "-sh" }
    :[allowArg="false",default="false"]
    :"Greets the user."
  SayBye
    :{"--say-bye", "-sb"} :{int}
    :[minValue="0",default="0"]
    :"Leaves."
  Help 
    :{"--help", "-h"}
    :[allowArg="false",default="false"]
    :"Displays this message."
FORMAT:: (SayHi | SayBye)* | Help;

2. Generate the parser

Execute:

clops 
  src/clops/foo.clo 
  -o=src/java/foo/clops -p=foo.clops

3. Use it!

src/java/foo/Main.java:

package foo;
import java.util.*;
import foo.clops.*;

public class Main {
 public static void main(String[]args){
  FooParser p = new FooParser();
  List<CLError> errors = p.parse(args);
  if (!errors.isEmpty()) {
   report(errors, System.err);
   p.printUsage(System.out);
  }
  FooOptionsInterface opt = 
    p.getOptionsInterface();
  if (opt.getHelp())
   p.printUsage(System.out);
  if (opt.getSayHi())
   System.out.println("hi");
  for (int i=opt.getSayBye(); --i>=0;)
   System.out.println("bye");
 }
}

Documentation

Tutorial

If you are new to CLOPS, this is the place to start.

Make sure you downloaded the latest release of CLOPS before going through the tutorial.

Reference

You are using CLOPS for a while but you can't remember the syntax for the choices property of the enum option type? The reference is what you want.

Got a question?

Mailing list

The best way to get help on using CLOPS is to write to its mailing list, clops-users@lists.sourceforge.net. To subscribe, use mailman.