CLI Release 2 is not available as a download yet, though it is via a snapshot though SVN.

It differs greatly from CLI version 1 and deserves to be released. Here is a sample application that demonstrates the most simple use case.

story

"I want to add a single option to a program and have it print out on System.out whether that option was added on the command line. The option may be entered as 'l', or '-length'".

Use Cases

I have included JUnit tests but here are the possibilities.

  1. call command without an option (eg calledCommand) which should display "didn't find '-l'"

2. call command with short option (eg calledCommand -l) which should display "found '-l'"

3. call command with long option (eg calledCommand --length) which should display "found '-l'"

4. call command with invalid long option (eg calledCommand --invalid) which should display some error.

5. call command with invalid short option (eg calledCommand -i) which should display some error.

I have included the source for both the application and the unit tests as attachements here.

!CLIDemoWithOneOptionNoArgument.java!

!CLIDemoWithOneOptionNoArgumentTest.java!

  • No labels