001 package jp.osdl.jbento2.analyzer; 002 003 import java.util.Iterator; 004 import org.apache.commons.cli.*; 005 006 public class AnalyzerCli { 007 008 public static void main(String[] args) throws Exception { 009 Options options = new Options(); 010 options.addOption( 011 OptionBuilder. 012 withArgName("source file"). 013 hasArg(). 014 withDescription("source file."). 015 withLongOpt("source"). 016 create("f")); 017 options.addOption( 018 OptionBuilder. 019 withArgName("dest dir"). 020 hasArg(). 021 withDescription("dest directory."). 022 withLongOpt("dest"). 023 create("d")); 024 options.addOption( 025 OptionBuilder. 026 withArgName("parser name"). 027 hasArg(). 028 withDescription("parser name. available value is 'jbento'."). 029 withLongOpt("parser"). 030 create("p")); 031 options.addOption( 032 OptionBuilder. 033 withArgName("ramp-up seconds"). 034 hasArg(). 035 withDescription("seconds to ignore ramp-up."). 036 withLongOpt("ramp-up"). 037 create("U")); 038 options.addOption( 039 OptionBuilder. 040 withArgName("ramp-down seconds"). 041 hasArg(). 042 withDescription("seconds to ignore ramp-down."). 043 withLongOpt("ramp-down"). 044 create("D")); 045 options.addOption( 046 OptionBuilder. 047 withArgName("duration seconds"). 048 hasArg(). 049 withDescription("seconds to duration."). 050 withLongOpt("duration"). 051 create("R")); 052 options.addOption("h", "help", false, "display help"); 053 054 CommandLineParser parser = new PosixParser(); 055 CommandLine line = null; 056 try { 057 line = parser.parse(options, args); 058 } catch (ParseException ex) { 059 throw ex; 060 } 061 062 if (line.hasOption("h") || 063 (line.getOptions().length == 0 && line.getArgs().length == 0)) { 064 HelpFormatter formatter = new HelpFormatter(); 065 formatter.printHelp("AnalyzerCli", options, true); 066 return; 067 } 068 069 Analyzer analyzer = new Analyzer(); 070 071 for (Iterator it = line.iterator(); it.hasNext();) { 072 Option o = (Option)it.next(); 073 String longOpt = o.getLongOpt(); 074 if (longOpt.equals("source")) { 075 analyzer.setSrc(o.getValue()); 076 } else if (longOpt.equals("dest")) { 077 analyzer.setDest(o.getValue()); 078 } else if (longOpt.equals("parser")) { 079 analyzer.setParser(o.getValue()); 080 } else if (longOpt.equals("ramp-up")) { 081 analyzer.setRampUpMillis(Integer.parseInt(o.getValue()) * 1000); 082 } else if (longOpt.equals("ramp-down")) { 083 analyzer.setRampDownMillis(Integer.parseInt(o.getValue()) * 1000); 084 } else if (longOpt.equals("duration")) { 085 analyzer.setDurationMillis(Long.parseLong(o.getValue()) * 1000); 086 } 087 } 088 089 if (analyzer.getSrc() == null) { 090 if (line.getArgs().length < 1) { 091 throw new MissingOptionException("source does not specified."); 092 } else { 093 analyzer.setSrc(line.getArgs()[0]); 094 } 095 } 096 097 analyzer.analyze(); 098 } 099 }