| 25 |
25 |
package com.soebes.supose.cli;
|
| 26 |
26 |
|
| 27 |
27 |
import java.io.IOException;
|
| 28 |
|
import java.io.PrintWriter;
|
| 29 |
|
import java.io.StringWriter;
|
| 30 |
28 |
import java.util.ArrayList;
|
|
29 |
import java.util.Iterator;
|
| 31 |
30 |
import java.util.List;
|
| 32 |
31 |
import java.util.Map;
|
| 33 |
32 |
|
| 34 |
33 |
import org.apache.commons.cli2.CommandLine;
|
|
34 |
import org.apache.commons.cli2.Group;
|
|
35 |
import org.apache.commons.cli2.HelpLine;
|
| 35 |
36 |
import org.apache.commons.cli2.OptionException;
|
| 36 |
37 |
import org.apache.commons.cli2.util.HelpFormatter;
|
|
38 |
import org.apache.commons.lang.StringUtils;
|
|
39 |
import org.apache.commons.lang.WordUtils;
|
| 37 |
40 |
import org.apache.log4j.Logger;
|
| 38 |
41 |
import org.apache.lucene.analysis.Analyzer;
|
| 39 |
42 |
import org.apache.lucene.analysis.standard.StandardAnalyzer;
|
| ... | ... | |
| 71 |
74 |
*/
|
| 72 |
75 |
public class SuposeCLI {
|
| 73 |
76 |
private static Logger LOGGER = Logger.getLogger(SuposeCLI.class);
|
|
77 |
|
|
78 |
private static final int HELP_OPTION_DESCRIPTION_INDENT = 30;
|
| 74 |
79 |
|
| 75 |
80 |
private static SuposeCommandLine suposecli = new SuposeCommandLine();
|
| 76 |
81 |
private static ScanRepository scanRepository = new ScanRepository();
|
| ... | ... | |
| 85 |
90 |
}
|
| 86 |
91 |
|
| 87 |
92 |
if (commandLine.hasOption(suposecli.getGlobalOptionH())) {
|
| 88 |
|
final StringWriter out = new StringWriter();
|
| 89 |
|
final HelpFormatter hf = new HelpFormatter();
|
| 90 |
|
hf.setGroup(suposecli.getSuposeOptions());
|
| 91 |
|
hf.setPrintWriter(new PrintWriter(out));
|
| 92 |
|
hf.printHelp();
|
| 93 |
|
System.out.println(out);
|
|
93 |
printHelp();
|
| 94 |
94 |
System.exit(0);
|
| 95 |
95 |
} else if (commandLine.hasOption(suposecli.getScanCommand())) {
|
| 96 |
96 |
runScan(suposecli.getScliScanCommand());
|
| ... | ... | |
| 105 |
105 |
System.exit(1);
|
| 106 |
106 |
}
|
| 107 |
107 |
}
|
|
108 |
|
|
109 |
private static void printHelp() {
|
|
110 |
StringBuffer help = new StringBuffer();
|
|
111 |
Group suposeOptions = suposecli.getSuposeOptions();
|
|
112 |
List helpLines = suposeOptions.helpLines(0, HelpFormatter.DEFAULT_DISPLAY_USAGE_SETTINGS, null);
|
|
113 |
String descriptionPad = StringUtils.repeat(" ", HELP_OPTION_DESCRIPTION_INDENT);
|
|
114 |
int descriptionIndent = HelpFormatter.DEFAULT_FULL_WIDTH - HELP_OPTION_DESCRIPTION_INDENT;
|
|
115 |
for (Iterator i = helpLines.iterator(); i.hasNext();) {
|
|
116 |
HelpLine helpLine = (HelpLine) i.next();
|
|
117 |
String usage = helpLine.usage(HelpFormatter.DEFAULT_LINE_USAGE_SETTINGS, null);
|
|
118 |
String usageWrapped = WordUtils.wrap(usage, HelpFormatter.DEFAULT_FULL_WIDTH);
|
|
119 |
help.append(usageWrapped).append("\n");
|
|
120 |
String description = helpLine.getDescription();
|
|
121 |
if (description != null) {
|
|
122 |
String descriptionWrapped = WordUtils.wrap(description, descriptionIndent, "\n" + descriptionPad, true);
|
|
123 |
help.append(descriptionPad).append(descriptionWrapped).append("\n");
|
|
124 |
}
|
|
125 |
}
|
|
126 |
System.out.println(help);
|
|
127 |
}
|
| 108 |
128 |
|
| 109 |
129 |
/**
|
| 110 |
130 |
* This will do the command argument extraction and give the parameter to
|