001    package jp.osdl.jbento2.report;
002    
003    import java.util.Iterator;
004    import org.apache.commons.cli.*;
005    
006    public class ReportCli {
007    
008        public static void main(String[] args) throws Exception {
009            Options options = new Options();
010            options.addOption(OptionBuilder.withArgName("source dir").hasArg()
011                    .withDescription("source dir.").withLongOpt("sourcedir")
012                    .isRequired().create("s"));
013            options.addOption(OptionBuilder.withArgName("dest dir").hasArg()
014                    .withDescription("dest dir.").withLongOpt("destdir")
015                    .create("d"));
016            options.addOption("h", "help", false, "display help");
017    
018            CommandLineParser parser = new PosixParser();
019            CommandLine line = null;
020            try {
021                line = parser.parse(options, args);
022            } catch (ParseException ex) {
023                throw ex;
024            }
025    
026            if (line.hasOption("h")
027                    || (line.getOptions().length == 0 && line.getArgs().length == 0)) {
028                HelpFormatter formatter = new HelpFormatter();
029                formatter.printHelp("ReportCli", options, true);
030                return;
031            }
032    
033            Report report = new Report();
034    
035            for (Iterator it = line.iterator(); it.hasNext();) {
036                Option o = (Option) it.next();
037                String longOpt = o.getLongOpt();
038                if (longOpt.equals("sourcedir")) {
039                    report.setSourceDir(o.getValue());
040                }
041                if (longOpt.equals("destdir")) {
042                    report.setDestDir(o.getValue());
043                }
044            }
045    
046            report.generate();
047        }
048    }