Posts

Showing posts with the label JCommander

Processing of empty args with required parameters AND help=true for one of the declared parameters

If you are using JCommander to parse your commander, you may encounter the situations shown below: You have an option that is required. For example: @Parameter(names = { "-i", "--input-file"}, description = "Input file [.bed]", required = true) private String input; If you run your program without args (empty args) using  SortBedErr.java , you will get the error message shown below: Exception in thread "main" com.beust.jcommander.ParameterException: The following option is required: -i, --input-file at com.beust.jcommander.JCommander.validateOptions(JCommander.java:321) at com.beust.jcommander.JCommander.parse(JCommander.java:283) at com.beust.jcommander.JCommander.parse(JCommander.java:265) at com.readbio.smRNACluster.bedtools.SortBed.main(SortBed.java:22) To sovle this problem, you can catch  ParameterException when the args is empty and print usage using usage() method. You can look into  SortBed.java  and get the detailed codes...

Parse command line parameter using JCommander in JAVA

Here I found a nice link about JCommander: https://blog.42.nl/articles/easy-command-line-interface-coding-with-jcommander/ Detailed mannual can be found @: http://jcommander.org/ To ask questions about JCommander, you can post you quesitons in the google group of JCommander: https://groups.google.com/forum/#!forum/jcommander