DVL1 dishevelled.org

Skip to: [content] [navigation]

dishevelled.org commandline 1.1 :: Downloads | Repository | Javadocs | Checkstyle | Test coverage | Changes


dishevelled.org commandline is a command line parser based on typed arguments. The commandline project requires java version 1.5 or later.


For example, given a Runnable whose constructor requires a String, a Date, and a List of URLs

 * My runnable.
public class MyRunnable
  implements Runnable

   * Create a new my runnable with the specified arguments.
   * @param arg0 string argument
   * @param arg1 date argument
   * @param arg2 list of URLs argument
  public MyRunnable(final String arg0, final Date arg1, final List<URL> arg2)
    // ...

its static void main(final String[] args) method might be implemented as

CommandLine commandLine = null;
ArgumentList arguments = null;
  // create typed command-line arguments to match runnable constructor arguments
  StringArgument arg0 = new StringArgument(...);
  DateArgument arg1 = new DateArgument(...);
  URLListArgument arg2 = new URLListArgument(...);

  // create an argument list
  arguments = new ArgumentList(arg0, arg1, arg2);

  // create a command line from String[] args
  commandLine = new CommandLine(args);

  // parse the command line with the argument list
  CommandLineParser.parse(commandLine, arguments);

  // instantiate the runnable with values returned by the typed arguments
  Runnable r = new MyRunnable(arg0.getValue(), arg1.getValue(), arg2.getValue());
catch (CommandLineParseException e)
  // thrown by CommandLineParser.parse(...)
  Usage.usage("java MyRunnable [args]", e, commandLine, arguments, System.err);
catch (IllegalArgumentException e)
  // possibly thrown by MyRunnable(...) constructor
  Usage.usage("java MyRunnable [args]", e, commandLine, arguments, System.err);


SourceForge.net Logo