use of org.apache.commons.cli.Option in project databus by linkedin.
the class CheckpointSerializerMain method createOptions.
@SuppressWarnings("static-access")
private static Options createOptions() {
Option helpOption = OptionBuilder.withLongOpt(HELP_OPT_NAME).withDescription(HELP_OPT_DESCR).create(HELP_OPT_CHAR);
Option clientPropsOption = OptionBuilder.withLongOpt(CLIENT_PROPS_FILE_OPT_NAME).withDescription(CLIENT_PROPS_FILE_OPT_DESCR).hasArg().withArgName("properties_file").create(CLIENT_PROPS_FILE_OPT_CHAR);
Option cp3PropsOption = OptionBuilder.withLongOpt(CP3_PROPS_FILE_OPT_NAME).withDescription(CP3_PROPS_FILE_OPT_DESCR).hasArg().withArgName("properties_file").create(CP3_PROPS_FILE_OPT_CHAR);
Option propsPrefixOption = OptionBuilder.withLongOpt(PROPS_PREFIX_OPT_NAME).withDescription(PROPS_PREFIX_OPT_DESCR).hasArg().withArgName("prefix_string").create(PROPS_PREFIX_OPT_CHAR);
Option sourcesOption = OptionBuilder.withLongOpt(SOURCES_OPT_NAME).withDescription(SOURCES_OPT_DESCR).hasArg().withArgName("sources_list").create(SOURCES_OPT_CHAR);
Option scnOptOption = OptionBuilder.withLongOpt(SCN_OPT_NAME).withDescription(SCN_OPT_DESCR).hasArg().withArgName("sequence_number").create(SCN_OPT_CHAR);
Option actionOption = OptionBuilder.withLongOpt(ACTION_OPT_NAME).withDescription(ACTION_OPT_DESCR).hasArg().withArgName("action").create(ACTION_OPT_CHAR);
Option sinceScnOptOption = OptionBuilder.withLongOpt(SINCE_SCN_OPT_NAME).withDescription(SINCE_SCN_OPT_DESCR).hasArg().withArgName("sequence_number").create(SINCE_SCN_OPT_CHAR);
Option startScnOptOption = OptionBuilder.withLongOpt(START_SCN_OPT_NAME).withDescription(START_SCN_OPT_DESCR).hasArg().withArgName("sequence_number").create(START_SCN_OPT_CHAR);
Option targetScnOptOption = OptionBuilder.withLongOpt(TARGET_SCN_OPT_NAME).withDescription(TARGET_SCN_OPT_DESCR).hasArg().withArgName("sequence_number").create(TARGET_SCN_OPT_CHAR);
Option typeOption = OptionBuilder.withLongOpt(TYPE_OPT_NAME).withDescription(TYPE_OPT_DESCR).hasArg().withArgName("checkpoint_type").create(TYPE_OPT_CHAR);
Option bootstrapSourceOption = OptionBuilder.withLongOpt(BOOTSTRAP_SOURCE_OPT_NAME).withDescription(BOOTSTRAP_SOURCE_OPT_DESCR).hasArg().withArgName("bootstrap_source_name").create(BOOTSTRAP_SOURCE_OPT_CHAR);
Options options = new Options();
options.addOption(helpOption);
options.addOption(actionOption);
options.addOption(clientPropsOption);
options.addOption(cp3PropsOption);
options.addOption(propsPrefixOption);
options.addOption(sourcesOption);
options.addOption(scnOptOption);
options.addOption(sinceScnOptOption);
options.addOption(startScnOptOption);
options.addOption(targetScnOptOption);
options.addOption(typeOption);
options.addOption(bootstrapSourceOption);
return options;
}
use of org.apache.commons.cli.Option in project Cloud9 by lintool.
the class LocalClusteringDriver method main.
// private static final String input="points_input";
@SuppressWarnings({ "static-access" })
public static void main(String[] args) {
Options options = new Options();
options.addOption(new Option(KMEANS, "initialize with k-means"));
options.addOption(new Option(HELP, "display help options"));
options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("input path").create(POINTS));
options.addOption(OptionBuilder.withArgName("num").hasArg().withDescription("output path").create(COMPONENTS));
options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("result path").create(OUTPUT));
CommandLine cmdline = null;
CommandLineParser parser = new GnuParser();
try {
cmdline = parser.parse(options, args);
} catch (ParseException exp) {
System.err.println("Error parsing command line: " + exp.getMessage());
}
if (!cmdline.hasOption(OUTPUT)) {
System.out.println("args: " + Arrays.toString(args));
HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(120);
formatter.printHelp(LocalClusteringDriver.class.getName(), options);
System.exit(-1);
}
if (cmdline.hasOption(HELP)) {
System.out.println("args: " + Arrays.toString(args));
HelpFormatter formatter = new HelpFormatter();
formatter.setWidth(120);
formatter.printHelp(LocalClusteringDriver.class.getName(), options);
System.exit(-1);
}
int numComponents = cmdline.hasOption(COMPONENTS) ? Integer.parseInt(cmdline.getOptionValue(COMPONENTS)) : 3;
int numPoints = cmdline.hasOption(POINTS) ? Integer.parseInt(cmdline.getOptionValue(POINTS)) : 100000;
String output = cmdline.getOptionValue(OUTPUT);
System.out.println(output);
System.out.println("Number of points: " + numPoints);
System.out.println("Number of components in mixture: " + numComponents);
UnivariateGaussianMixtureModel sourceModel = new UnivariateGaussianMixtureModel(numComponents);
for (int i = 0; i < numComponents; i++) {
PVector param = new PVector(2);
param.array[0] = RANDOM.nextInt(100);
param.array[1] = RANDOM.nextFloat() * 3;
sourceModel.param[i] = param;
sourceModel.weight[i] = RANDOM.nextInt(10) + 1;
}
sourceModel.normalizeWeights();
System.out.println("Initial mixture model:\n" + sourceModel + "\n");
// Draw points from initial mixture model and compute the n clusters
Point[] points = sourceModel.drawRandomPoints(numPoints);
UnivariateGaussianMixtureModel learnedModel = null;
if (cmdline.hasOption(KMEANS)) {
System.out.println("Running k-means to initialize clusters...");
List<Point>[] clusters = KMeans.run(points, numComponents);
double[] means = new double[numComponents];
int cnt = 0;
for (List<Point> cluster : clusters) {
double tmp = 0.0;
for (Point p : cluster) {
tmp += p.value;
}
means[cnt] = tmp / cluster.size();
cnt++;
}
System.out.println("Cluster means: " + Arrays.toString(means) + "\n");
learnedModel = ExpectationMaximization.initialize(points, means);
} else {
learnedModel = ExpectationMaximization.initialize(points, numComponents);
}
Path outputPoi = new Path(output);
try {
FileSystem fs = FileSystem.get(new Configuration());
fs.delete(outputPoi, true);
FSDataOutputStream pointfile = fs.create(new Path(output + "/points"));
for (int i = 0; i < numPoints; i++) {
pointfile.write((Double.toString(points[i].value) + "\n").getBytes());
}
pointfile.flush();
pointfile.close();
FSDataOutputStream clusterfile = fs.create(new Path(output + "/cluster0"));
for (int i = 0; i < numComponents; i++) {
clusterfile.write((i + " " + Double.toString(learnedModel.weight[i]) + " " + learnedModel.param[i].array[0] + " " + learnedModel.param[i].array[1] + "\n").getBytes());
}
clusterfile.flush();
clusterfile.close();
} catch (IOException exp) {
exp.printStackTrace();
}
System.out.println("** Ready to run EM **\n");
System.out.println("Initial mixture model:\n" + learnedModel + "\n");
learnedModel = ExpectationMaximization.run(points, learnedModel);
System.out.println("Mixure model estimated using EM: \n" + learnedModel + "\n");
}
use of org.apache.commons.cli.Option in project saga by timurstrekalov.
the class Main method main.
public static void main(final String[] args) throws IOException, ParseException {
logger.debug("Starting...");
final Option baseDirOpt = new Option("b", "base-dir", true, "Base directory for test search");
final Option includeOpt = new Option("i", "include", true, "Comma-separated list of Ant-style paths to the tests to run");
final Option excludeOpt = new Option("e", "exclude", true, "Comma-separated list of Ant-style paths to the tests to exclude from run");
final Option outputDirOpt = new Option("o", "output-dir", true, "The output directory for coverage reports");
final Option outputInstrumentedFilesOpt = new Option("f", "output-instrumented-files", false, "Whether to output instrumented files (default is false)");
final Option noInstrumentPatternOpt = new Option("n", "no-instrument-pattern", true, "Regular expression patterns to match classes to exclude from instrumentation");
noInstrumentPatternOpt.setArgs(Option.UNLIMITED_VALUES);
final Option sourcesToPreloadOpt = new Option("p", "preload-sources", true, "Comma-separated list of Ant-style paths to files to preload");
final Option sourcesToPreloadEncodingOpt = new Option(null, "preload-sources-encoding", true, "Encoding to use when preloading sources");
final Option threadCountOpt = new Option("t", "thread-count", true, "The maximum number of threads to use (defaults to the number of cores)");
final Option outputStrategyOpt = new Option("s", "output-strategy", true, "Coverage report output strategy. One of " + Arrays.toString(OutputStrategy.values()));
final Option includeInlineScriptsOpt = new Option("d", "include-inline-scripts", false, "Whether to include inline scripts into instrumentation by default (default is false)");
final Option backgroundJavaScriptTimeoutOpt = new Option("j", "background-javascript-timeout", true, "How long to wait for background JavaScript to finish running (in milliseconds, default is 5 minutes)");
final Option browserVersionOpt = new Option("v", "browser-version", true, "Determines the browser and version profile that HtmlUnit will simulate");
final Option reportFormatsOpt = new Option(null, "report-formats", true, "A comma-separated list of formats of the reports to be generated. Valid values are: HTML, RAW, CSV, PDF");
final Option sortByOpt = new Option(null, "sort-by", true, "The column to sort by, one of 'file', 'statements', 'executed' or 'coverage' (default is 'coverage')");
final Option orderOpt = new Option(null, "order", true, "The order of sorting, one of 'asc' or 'ascending', 'desc' or 'descending' (default is 'ascending')");
final Option helpOpt = new Option("h", "help", false, "Print this message");
final Options options = new Options();
options.addOption(baseDirOpt);
options.addOption(includeOpt);
options.addOption(excludeOpt);
options.addOption(outputDirOpt);
options.addOption(outputInstrumentedFilesOpt);
options.addOption(noInstrumentPatternOpt);
options.addOption(threadCountOpt);
options.addOption(outputStrategyOpt);
options.addOption(includeInlineScriptsOpt);
options.addOption(helpOpt);
options.addOption(sourcesToPreloadOpt);
options.addOption(sourcesToPreloadEncodingOpt);
options.addOption(backgroundJavaScriptTimeoutOpt);
options.addOption(browserVersionOpt);
options.addOption(reportFormatsOpt);
options.addOption(sortByOpt);
options.addOption(orderOpt);
logger.debug("Finished configuring options");
try {
CommandLineParser parser = new GnuParser();
CommandLine line = parser.parse(options, args, false);
logger.debug("Parsed the arguments, take 1");
baseDirOpt.setRequired(true);
outputDirOpt.setRequired(true);
options.addOption(baseDirOpt);
options.addOption(outputDirOpt);
if (line.hasOption(helpOpt.getLongOpt())) {
printHelpAndExit(options);
}
parser = new GnuParser();
line = parser.parse(options, args);
logger.debug("Parsed the arguments, take 2");
final String baseDir = line.getOptionValue(baseDirOpt.getLongOpt());
final String includes = line.getOptionValue(includeOpt.getLongOpt());
final String excludes = line.getOptionValue(excludeOpt.getLongOpt());
final File outputDir = new File(line.getOptionValue(outputDirOpt.getLongOpt()));
final CoverageGenerator gen = CoverageGeneratorFactory.newInstance(baseDir, outputDir);
final Config config = gen.getConfig();
config.setIncludes(includes);
config.setExcludes(excludes);
if (line.hasOption(outputInstrumentedFilesOpt.getLongOpt())) {
config.setOutputInstrumentedFiles(true);
}
config.setNoInstrumentPatterns(line.getOptionValues(noInstrumentPatternOpt.getLongOpt()));
config.setSourcesToPreload(line.getOptionValue(sourcesToPreloadOpt.getLongOpt()));
config.setOutputStrategy(line.getOptionValue(outputStrategyOpt.getLongOpt()));
final String threadCount = line.getOptionValue(threadCountOpt.getLongOpt());
if (threadCount != null) {
try {
config.setThreadCount(Integer.parseInt(threadCount));
} catch (final Exception e) {
System.err.println("Invalid thread count");
printHelpAndExit(options);
}
}
if (line.hasOption(includeInlineScriptsOpt.getLongOpt())) {
config.setIncludeInlineScripts(true);
}
final String backgroundJavaScriptTimeout = line.getOptionValue(backgroundJavaScriptTimeoutOpt.getLongOpt());
if (backgroundJavaScriptTimeout != null) {
try {
config.setBackgroundJavaScriptTimeout(Long.valueOf(backgroundJavaScriptTimeout));
} catch (final Exception e) {
System.err.println("Invalid timeout");
printHelpAndExit(options);
}
}
config.setBrowserVersion(line.getOptionValue(browserVersionOpt.getLongOpt()));
config.setReportFormats(line.getOptionValue(reportFormatsOpt.getLongOpt()));
config.setSortBy(line.getOptionValue(sortByOpt.getLongOpt()));
config.setOrder(line.getOptionValue(orderOpt.getLongOpt()));
logger.debug("Configured the coverage generator, running");
gen.instrumentAndGenerateReports();
} catch (final MissingOptionException e) {
System.err.println(e.getMessage());
printHelpAndExit(options);
} catch (final UnrecognizedOptionException e) {
System.err.println(e.getMessage());
printHelpAndExit(options);
} catch (final ParseException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
use of org.apache.commons.cli.Option in project solo by b3log.
the class Starter method main.
/**
* Main.
*
* @param args the specified arguments
* @throws java.lang.Exception if start failed
*/
public static void main(final String[] args) throws Exception {
final Logger logger = Logger.getLogger(Starter.class);
final Options options = new Options();
final Option listenPortOpt = Option.builder("lp").longOpt("listen_port").argName("LISTEN_PORT").hasArg().desc("listen port, default is 8080").build();
options.addOption(listenPortOpt);
final Option serverSchemeOpt = Option.builder("ss").longOpt("server_scheme").argName("SERVER_SCHEME").hasArg().desc("browser visit protocol, default is http").build();
options.addOption(serverSchemeOpt);
final Option serverHostOpt = Option.builder("sh").longOpt("server_host").argName("SERVER_HOST").hasArg().desc("browser visit domain name, default is localhost").build();
options.addOption(serverHostOpt);
final Option serverPortOpt = Option.builder("sp").longOpt("server_port").argName("SERVER_PORT").hasArg().desc("browser visit port, default is 8080").build();
options.addOption(serverPortOpt);
final Option staticServerSchemeOpt = Option.builder("sss").longOpt("static_server_scheme").argName("STATIC_SERVER_SCHEME").hasArg().desc("browser visit static resource protocol, default is http").build();
options.addOption(staticServerSchemeOpt);
final Option staticServerHostOpt = Option.builder("ssh").longOpt("static_server_host").argName("STATIC_SERVER_HOST").hasArg().desc("browser visit static resource domain name, default is localhost").build();
options.addOption(staticServerHostOpt);
final Option staticServerPortOpt = Option.builder("ssp").longOpt("static_server_port").argName("STATIC_SERVER_PORT").hasArg().desc("browser visit static resource port, default is 8080").build();
options.addOption(staticServerPortOpt);
final Option runtimeModeOpt = Option.builder("rm").longOpt("runtime_mode").argName("RUNTIME_MODE").hasArg().desc("runtime mode (DEVELOPMENT/PRODUCTION), default is DEVELOPMENT").build();
options.addOption(runtimeModeOpt);
options.addOption("h", "help", false, "print help for the command");
final HelpFormatter helpFormatter = new HelpFormatter();
final CommandLineParser commandLineParser = new DefaultParser();
CommandLine commandLine;
final boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
final String cmdSyntax = isWindows ? "java -cp WEB-INF/lib/*;WEB-INF/classes org.b3log.solo.Starter" : "java -cp WEB-INF/lib/*:WEB-INF/classes org.b3log.solo.Starter";
final String header = "\nSolo is a blogging system written in Java, feel free to create your or your team own blog.\nSolo 是一个用 Java 实现的博客系统,为你或你的团队创建个博客吧。\n\n";
final String footer = "\nReport bugs or request features please visit our project website: https://github.com/b3log/solo\n\n";
try {
commandLine = commandLineParser.parse(options, args);
} catch (final ParseException e) {
helpFormatter.printHelp(cmdSyntax, header, options, footer, true);
return;
}
if (commandLine.hasOption("h")) {
helpFormatter.printHelp(cmdSyntax, header, options, footer, true);
return;
}
String portArg = commandLine.getOptionValue("listen_port");
if (!Strings.isNumeric(portArg)) {
portArg = "8080";
}
String serverScheme = commandLine.getOptionValue("server_scheme");
Latkes.setServerScheme(serverScheme);
String serverHost = commandLine.getOptionValue("server_host");
Latkes.setServerHost(serverHost);
String serverPort = commandLine.getOptionValue("server_port");
Latkes.setServerPort(serverPort);
String staticServerScheme = commandLine.getOptionValue("static_server_scheme");
Latkes.setStaticServerScheme(staticServerScheme);
String staticServerHost = commandLine.getOptionValue("static_server_host");
Latkes.setStaticServerHost(staticServerHost);
String staticServerPort = commandLine.getOptionValue("static_server_port");
Latkes.setStaticServerPort(staticServerPort);
String runtimeMode = commandLine.getOptionValue("runtime_mode");
if (null != runtimeMode) {
Latkes.setRuntimeMode(RuntimeMode.valueOf(runtimeMode));
}
// For Latke IoC
Latkes.setScanPath("org.b3log.solo");
logger.info("Standalone mode, see [https://github.com/b3log/solo/wiki/standalone_mode] for more details.");
Latkes.initRuntimeEnv();
// POM structure in dev env
String webappDirLocation = "src/main/webapp/";
final File file = new File(webappDirLocation);
if (!file.exists()) {
// production environment
webappDirLocation = ".";
}
final int port = Integer.valueOf(portArg);
final Server server = new Server(port);
final WebAppContext root = new WebAppContext();
// Use parent class loader
root.setParentLoaderPriority(true);
root.setContextPath("/");
root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml");
root.setResourceBase(webappDirLocation);
server.setHandler(root);
try {
server.start();
} catch (final Exception e) {
logger.log(Level.ERROR, "Server start failed", e);
System.exit(-1);
}
serverScheme = Latkes.getServerScheme();
serverHost = Latkes.getServerHost();
serverPort = Latkes.getServerPort();
final String contextPath = Latkes.getContextPath();
try {
Desktop.getDesktop().browse(new URI(serverScheme + "://" + serverHost + ":" + serverPort + contextPath));
} catch (final Throwable e) {
// Ignored
}
server.join();
}
use of org.apache.commons.cli.Option in project goci by EBISPOT.
the class ParentMappingApplication method bindOptions.
private static Options bindOptions() {
Options options = new Options();
// help
Option helpOption = new Option("h", "help", false, "Print the help");
options.addOption(helpOption);
// add output file arguments
Option outputFileOption = new Option("o", "output", true, "The output file to write the mapped traits to");
outputFileOption.setArgName("file");
outputFileOption.setRequired(true);
options.addOption(outputFileOption);
return options;
}
Aggregations