The Java version of the Args Program.
Java
Latest commit 77e6426 Dec 18, 2014 @unclebob Map Arguments
Permalink
Failed to load latest commit information.
.idea/inspectionProfiles update to cleancoder status Nov 24, 2014
src/com/cleancoder/args Map Arguments Dec 18, 2014
test/com/cleancoder/args Map Arguments Dec 18, 2014
.gitignore
README Added to README Dec 2, 2014
build.xml update to cleancoder status Nov 24, 2014

README

This is the java version of the Args program described in: http://butunclebob.com/ArticleS.UncleBob.CleanCodeArgs

public class ArgsMain {
  public static void main(String[] args) {
    try {
      Args arg = new Args("l,p#,d*", args);
      boolean logging = arg.getBoolean('l');
      int port = arg.getInt('p');
      String directory = arg.getString('d');
      executeApplication(logging, port, directory);
    } catch (ArgsException e) {
      System.out.printf("Argument error: %s\n", e.errorMessage());
    }
  }

  private static void executeApplication(boolean logging, int port, String directory) {
    System.out.printf("logging is %s, port:%d, directory:%s\n",logging, port, directory);
  }
}

Schema:
 - char    - Boolean arg.
 - char*   - String arg.
 - char#   - Integer arg.
 - char##  - double arg.
 - char[*] - one element of a string array.

Example schema: (f,s*,n#,a##,p[*])
Coresponding command line: "-f -s Bob -n 1 -a 3.2 -p e1 -p e2 -p e3