001    package jp.osdl.jbento2.analyzer;
002    
003    import java.io.IOException;
004    import java.util.Iterator;
005    
006    import org.apache.commons.cli.*;
007    
008    public class MultiResultCollectorCli {
009    
010        public static void main(String[] args) throws ParseException, IOException {
011            Options options = new Options();
012            options.addOption(
013                OptionBuilder.
014                withArgName("source dir").
015                hasArg().
016                withDescription("source directory.").
017                withLongOpt("sourcedir").
018                create("s"));
019            options.addOption(
020                OptionBuilder.
021                withArgName("dest dir").
022                hasArg().
023                withDescription("destination directory.").
024                withLongOpt("dest").
025                create("d"));
026            
027            if (args.length == 0) {
028                HelpFormatter formatter = new HelpFormatter();
029                formatter.printHelp("MultiResultCollectorCli", options, true);
030                return;
031            }
032    
033            CommandLineParser parser = new PosixParser();
034            CommandLine line = null;
035            try {
036                line = parser.parse(options, args);
037            } catch (ParseException ex) {
038                throw ex;
039            }
040    
041            if (line.hasOption("h") ||
042                (line.getOptions().length == 0 && line.getArgs().length == 0)) {
043                HelpFormatter formatter = new HelpFormatter();
044                formatter.printHelp("MultiResultCollector", options, true);
045                return;           
046            }
047    
048            MultiResultCollector collector = new MultiResultCollector();
049    
050            for (Iterator it = line.iterator(); it.hasNext();) {
051                Option o = (Option)it.next();
052                String longOpt = o.getLongOpt();
053                if (longOpt.equals("sourcedir")) {
054                    collector.setSrcDir(o.getValue());
055                } else if (longOpt.equals("dest")) {
056                    collector.setDestDir(o.getValue());
057                }
058            }
059    
060            if (collector.getSrcDir() == null) {
061                if (line.getArgs().length < 1) {
062                    throw new MissingOptionException("source does not specified.");
063                } else {
064                    collector.setSrcDir(line.getArgs()[0]);
065                }
066            }
067            collector.analyze();
068        }
069    }