use of org.apache.commons.cli.Options in project streamsx.health by IBMStreams.
the class PrintService method main.
public static void main(String[] args) throws Exception {
Option subscribeTopicOption = Option.builder("s").longOpt("subscribe-topic").hasArg().argName("subscribe topic").required().build();
Option contextTypeOption = Option.builder("c").longOpt("context-type").hasArg().argName("context type").required(false).build();
Options options = new Options();
options.addOption(subscribeTopicOption);
options.addOption(contextTypeOption);
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("help", options);
throw (e);
}
Type contextType = Type.valueOf(cmd.getOptionValue("c", Type.DISTRIBUTED.name()));
String subscribeTopic = cmd.getOptionValue("s");
PrintService svc = new PrintService(subscribeTopic);
svc.run(contextType, new HashMap<String, Object>());
}
use of org.apache.commons.cli.Options in project streamsx.health by IBMStreams.
the class AbstractEventService method launchService.
protected static void launchService(String[] args, Class<? extends AbstractEventService> eventServiceClass) throws Exception {
Option hostOption = Option.builder("x").longOpt("host").hasArg().argName("watson explorer host").required().build();
Option portOption = Option.builder("p").longOpt("port").hasArg().argName("watson explorer port").required().build();
Option collectionOption = Option.builder("c").longOpt("collection").hasArg().argName("collection name").required().build();
Option patientIdFieldOption = Option.builder("f").longOpt("patient-field").hasArg().argName("patient ID field name").required(false).build();
Option toolkitOption = Option.builder("t").longOpt("toolkit-path").hasArg().argName("watson explorer toolkit path").required().build();
Option subscribeOption = Option.builder("s").longOpt("subscription-topic").hasArg().argName("subscription topic").required().build();
Option debugOption = Option.builder("d").longOpt("debug").hasArg().argName("isDebugEnabled").required(false).type(Boolean.class).build();
Options options = new Options();
options.addOption(hostOption);
options.addOption(portOption);
options.addOption(collectionOption);
options.addOption(patientIdFieldOption);
options.addOption(toolkitOption);
options.addOption(subscribeOption);
options.addOption(debugOption);
CommandLineParser parser = new DefaultParser();
CommandLine cmd = null;
try {
cmd = parser.parse(options, args);
} catch (ParseException e) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("help", options);
throw (e);
}
boolean isDebug = cmd.getOptionValue("d", "false").equals("true");
AbstractEventService svc = eventServiceClass.getConstructor(String.class).newInstance(cmd.getOptionValue("t"));
//MedicationEventService svc = new MedicationEventService(cmd.getOptionValue("t"));
svc.setContextType(Type.DISTRIBUTED);
svc.addSubmissionTimeParam("wex.host", cmd.getOptionValue("x"));
svc.addSubmissionTimeParam("wex.port", Integer.valueOf(cmd.getOptionValue("p")));
svc.addSubmissionTimeParam("wex.patient.field.name", cmd.getOptionValue("f", "patient_id"));
svc.addSubmissionTimeParam("collectionName", cmd.getOptionValue("c"));
svc.setSubscriptionTopic(cmd.getOptionValue("s"));
if (isDebug) {
svc.setTraceLevel(TraceLevel.TRACE);
}
svc.buildAndRun();
if (isDebug) {
new EventBeacon(svc.getPublishedTopic()).run();
}
}
use of org.apache.commons.cli.Options in project midpoint by Evolveum.
the class Upload method main.
public static void main(String[] args) {
try {
Options options = new Options();
options.addOption(OPT_HELP, "help", false, "Print this help information");
options.addOption(OPT_FILE_TO_UPLOAD, "file", true, "File to be uploaded (XML for the moment)");
options.addOption(OPT_DIR_TO_UPLOAD, "dir", true, "Whole directory to be uploaded (XML files only for the moment)");
options.addOption(OPT_URL, true, "Endpoint URL (default: " + DEFAULT_ENDPOINT_URL + ")");
options.addOption(OPT_USER, "user", true, "User name (default: " + ADM_USERNAME + ")");
options.addOption(OPT_PASSWORD, "password", true, "Password");
options.addOption(OPT_FILE_FOR_RESULT, "file-for-result", true, "Name of the file to write operation result into");
options.addOption(OPT_HIDE_RESULT, "hide-result", false, "Don't display detailed operation result (default: showing if not SUCCESS)");
options.addOption(OPT_SHOW_RESULT, "show-result", false, "Always show detailed operation result (default: showing if not SUCCESS)");
CommandLineParser parser = new GnuParser();
CommandLine cmdline = parser.parse(options, args);
if (cmdline.hasOption(OPT_HELP) || (!cmdline.hasOption(OPT_FILE_TO_UPLOAD) && !cmdline.hasOption(OPT_DIR_TO_UPLOAD))) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("upload", options);
System.out.println("\nNote that currently it is possible to upload only one object per file (i.e. no <objects> tag), and the " + "file must be written using fully specified XML namespaces (i.e. namespace-guessing algorithm allowing to write data " + "without namespaces is not available).");
System.exit(-1);
}
System.out.println("=================================================================");
ModelPortType modelPort = createModelPort(cmdline);
if (cmdline.hasOption(OPT_FILE_TO_UPLOAD)) {
uploadFile(new File(cmdline.getOptionValue(OPT_FILE_TO_UPLOAD)), cmdline, modelPort);
}
if (cmdline.hasOption(OPT_DIR_TO_UPLOAD)) {
uploadDir(cmdline.getOptionValue(OPT_DIR_TO_UPLOAD), cmdline, modelPort);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
if (error) {
System.exit(-1);
}
}
use of org.apache.commons.cli.Options in project tika by apache.
the class CommandLineParserBuilder method build.
public Options build(InputStream is) throws IOException {
Document doc = null;
try {
DocumentBuilder docBuilder = new ParseContext().getDocumentBuilder();
doc = docBuilder.parse(is);
} catch (TikaException | SAXException e) {
throw new IOExceptionWithCause(e);
}
Node docElement = doc.getDocumentElement();
NodeList children = docElement.getChildNodes();
Node commandlineNode = null;
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
String nodeName = child.getNodeName();
if (nodeName.equals("commandline")) {
commandlineNode = child;
break;
}
}
Options options = new Options();
if (commandlineNode == null) {
return options;
}
NodeList optionNodes = commandlineNode.getChildNodes();
for (int i = 0; i < optionNodes.getLength(); i++) {
Node optionNode = optionNodes.item(i);
if (optionNode.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Option opt = buildOption(optionNode);
if (opt != null) {
options.addOption(opt);
}
}
return options;
}
use of org.apache.commons.cli.Options in project compiler by boalang.
the class BoaMain method main.
public static void main(final String[] args) throws IOException {
final Options options = new Options();
options.addOption("p", "parse", false, "parse and semantic check a Boa program (don't generate code)");
options.addOption("c", "compile", false, "compile a Boa program");
options.addOption("e", "execute", false, "execute a Boa program locally");
options.addOption("g", "generate", false, "generate a Boa dataset");
try {
if (args.length == 0) {
printHelp(options, null);
return;
} else {
final CommandLine cl = new PosixParser().parse(options, new String[] { args[0] });
final String[] tempargs = new String[args.length - 1];
System.arraycopy(args, 1, tempargs, 0, args.length - 1);
if (cl.hasOption("c")) {
boa.compiler.BoaCompiler.main(tempargs);
} else if (cl.hasOption("p")) {
boa.compiler.BoaCompiler.parseOnly(tempargs);
} else if (cl.hasOption("e")) {
boa.evaluator.BoaEvaluator.main(tempargs);
} else if (cl.hasOption("g")) {
boa.datagen.BoaGenerator.main(tempargs);
}
}
} catch (final org.apache.commons.cli.ParseException e) {
printHelp(options, e.getMessage());
}
}
Aggregations