List of usage examples for org.apache.commons.cli OptionGroup setRequired
public void setRequired(boolean required)
From source file:com.enioka.jqm.tools.Main.java
/** * Startup method for the packaged JAR//from www . j a va 2 s. c o m * * @param args * 0 is node name */ @SuppressWarnings("static-access") public static void main(String[] args) { Helpers.setLogFileName("cli"); Option o00 = OptionBuilder.withArgName("nodeName").hasArg().withDescription("name of the JQM node to start") .isRequired().create("startnode"); Option o01 = OptionBuilder.withDescription("display help").withLongOpt("help").create("h"); Option o11 = OptionBuilder.withArgName("applicationname").hasArg() .withDescription("name of the application to launch").isRequired().create("enqueue"); Option o21 = OptionBuilder.withArgName("xmlpath").hasArg() .withDescription("path of the XML configuration file to import").isRequired() .create("importjobdef"); Option o31 = OptionBuilder.withArgName("xmlpath").hasArg() .withDescription("export all queue definitions into an XML file").isRequired() .create("exportallqueues"); OptionBuilder.withArgName("xmlpath").hasArg() .withDescription("export some queue definitions into an XML file").isRequired() .create("exportqueuefile"); OptionBuilder.withArgName("queues").hasArg().withDescription("queues to export").withValueSeparator(',') .isRequired().create("queue"); Option o51 = OptionBuilder.withArgName("xmlpath").hasArg() .withDescription("import all queue definitions from an XML file").isRequired() .create("importqueuefile"); Option o61 = OptionBuilder.withArgName("nodeName").hasArg() .withDescription("creates a JQM node of this name, or updates it if it exists. Implies -u.") .isRequired().create("createnode"); Option o71 = OptionBuilder.withDescription("display JQM engine version").withLongOpt("version").create("v"); Option o81 = OptionBuilder.withDescription("upgrade JQM database").withLongOpt("upgrade").create("u"); Option o91 = OptionBuilder.withArgName("jobInstanceId").hasArg() .withDescription("get job instance status by ID").isRequired().withLongOpt("getstatus").create("g"); Option o101 = OptionBuilder.withArgName("password").hasArg() .withDescription("creates or resets root admin account password").isRequired().withLongOpt("root") .create("r"); Option o111 = OptionBuilder.withArgName("option").hasArg() .withDescription( "ws handling. Possible values are: enable, disable, ssl, nossl, internalpki, externalapi") .isRequired().withLongOpt("gui").create("w"); Option o121 = OptionBuilder.withArgName("id[,logfilepath]").hasArg().withDescription("single launch mode") .isRequired().withLongOpt("gui").create("s"); Option o131 = OptionBuilder.withArgName("resourcefile").hasArg() .withDescription("resource parameter file to use. Default is resources.xml") .withLongOpt("resources").create("p"); Option o141 = OptionBuilder.withArgName("login,password,role1,role2,...").hasArgs(Option.UNLIMITED_VALUES) .withValueSeparator(',') .withDescription("Create or update a JQM account. Roles must exist beforehand.").create("U"); Options options = new Options(); OptionGroup og1 = new OptionGroup(); og1.setRequired(true); og1.addOption(o00); og1.addOption(o01); og1.addOption(o11); og1.addOption(o21); og1.addOption(o31); og1.addOption(o51); og1.addOption(o61); og1.addOption(o71); og1.addOption(o81); og1.addOption(o91); og1.addOption(o101); og1.addOption(o111); og1.addOption(o121); og1.addOption(o141); options.addOptionGroup(og1); OptionGroup og2 = new OptionGroup(); og2.addOption(o131); options.addOptionGroup(og2); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(160); try { // Parse arguments CommandLineParser parser = new BasicParser(); CommandLine line = parser.parse(options, args); // Other db connection? if (line.getOptionValue(o131.getOpt()) != null) { jqmlogger.info("Using resource XML file " + line.getOptionValue(o131.getOpt())); Helpers.resourceFile = line.getOptionValue(o131.getOpt()); } // Set db connection Helpers.registerJndiIfNeeded(); // Enqueue if (line.getOptionValue(o11.getOpt()) != null) { enqueue(line.getOptionValue(o11.getOpt())); } // Get status if (line.getOptionValue(o91.getOpt()) != null) { getStatus(Integer.parseInt(line.getOptionValue(o91.getOpt()))); } // Import XML else if (line.getOptionValue(o21.getOpt()) != null) { importJobDef(line.getOptionValue(o21.getOpt())); } // Start engine else if (line.getOptionValue(o00.getOpt()) != null) { startEngine(line.getOptionValue(o00.getOpt())); } // Export all Queues else if (line.getOptionValue(o31.getOpt()) != null) { exportAllQueues(line.getOptionValue(o31.getOpt())); } // Import queues else if (line.getOptionValue(o51.getOpt()) != null) { importQueues(line.getOptionValue(o51.getOpt())); } // Create node else if (line.getOptionValue(o61.getOpt()) != null) { createEngine(line.getOptionValue(o61.getOpt())); } // Upgrade else if (line.hasOption(o81.getOpt())) { upgrade(); } // Help else if (line.hasOption(o01.getOpt())) { formatter.printHelp("java -jar jqm-engine.jar", options, true); } // Version else if (line.hasOption(o71.getOpt())) { jqmlogger.info("Engine version: " + Helpers.getMavenVersion()); } // Root password else if (line.hasOption(o101.getOpt())) { root(line.getOptionValue(o101.getOpt())); } // Web options else if (line.hasOption(o111.getOpt())) { ws(line.getOptionValue(o111.getOpt())); } // Web options else if (line.hasOption(o121.getOpt())) { single(line.getOptionValue(o121.getOpt())); } // User handling else if (line.hasOption(o141.getOpt())) { user(line.getOptionValues(o141.getOpt())); } } catch (ParseException exp) { jqmlogger.fatal("Could not read command line: " + exp.getMessage()); formatter.printHelp("java -jar jqm-engine.jar", options, true); return; } }
From source file:edu.wisc.doit.tcrypt.cli.TokenCrypt.java
public static void main(String[] args) throws IOException { // create Options object final Options options = new Options(); // operation opt group final OptionGroup cryptTypeGroup = new OptionGroup(); cryptTypeGroup.addOption(new Option("e", "encrypt", false, "Encrypt a token")); cryptTypeGroup.addOption(new Option("d", "decrypt", false, "Decrypt a token")); cryptTypeGroup//w ww .j a v a 2 s . c om .addOption(new Option("c", "check", false, "Check if the string looks like an encrypted token")); cryptTypeGroup.setRequired(true); options.addOptionGroup(cryptTypeGroup); // token source opt group final OptionGroup tokenGroup = new OptionGroup(); final Option tokenOpt = new Option("t", "token", true, "The token(s) to operate on"); tokenOpt.setArgs(Option.UNLIMITED_VALUES); tokenGroup.addOption(tokenOpt); final Option tokenFileOpt = new Option("f", "file", true, "A file with one token per line to operate on, if - is specified stdin is used"); tokenGroup.addOption(tokenFileOpt); tokenGroup.setRequired(true); options.addOptionGroup(tokenGroup); final Option keyOpt = new Option("k", "keyFile", true, "Key file to use. Must be a private key for decryption and a public key for encryption"); keyOpt.setRequired(true); options.addOption(keyOpt); // create the parser final CommandLineParser parser = new GnuParser(); CommandLine line = null; try { // parse the command line arguments line = parser.parse(options, args); } catch (ParseException exp) { // automatically generate the help statement System.err.println(exp.getMessage()); final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java " + TokenCrypt.class.getName(), options, true); System.exit(1); } final Reader keyReader = createKeyReader(line); final TokenHandler tokenHandler = createTokenHandler(line, keyReader); if (line.hasOption("t")) { //tokens on cli final String[] tokens = line.getOptionValues("t"); for (final String token : tokens) { handleToken(tokenHandler, token); } } else { //tokens from a file final String tokenFile = line.getOptionValue("f"); final BufferedReader fileReader; if ("-".equals(tokenFile)) { fileReader = new BufferedReader(new InputStreamReader(System.in)); } else { fileReader = new BufferedReader(new FileReader(tokenFile)); } while (true) { final String token = fileReader.readLine(); if (token == null) { break; } handleToken(tokenHandler, token); } } }
From source file:com.example.dlp.Inspect.java
/** * Command line application to inspect data using the Data Loss Prevention API. * Supported data formats: string, file, text file on GCS, BigQuery table, and Datastore entity *///from w w w . ja va 2 s .c o m public static void main(String[] args) throws Exception { OptionGroup optionsGroup = new OptionGroup(); optionsGroup.setRequired(true); Option stringOption = new Option("s", "string", true, "inspect string"); optionsGroup.addOption(stringOption); Option fileOption = new Option("f", "file path", true, "inspect input file path"); optionsGroup.addOption(fileOption); Option gcsOption = new Option("gcs", "Google Cloud Storage", false, "inspect GCS file"); optionsGroup.addOption(gcsOption); Option datastoreOption = new Option("ds", "Google Datastore", false, "inspect Datastore kind"); optionsGroup.addOption(datastoreOption); Option bigqueryOption = new Option("bq", "Google BigQuery", false, "inspect BigQuery table"); optionsGroup.addOption(bigqueryOption); Options commandLineOptions = new Options(); commandLineOptions.addOptionGroup(optionsGroup); Option minLikelihoodOption = Option.builder("minLikelihood").hasArg(true).required(false).build(); commandLineOptions.addOption(minLikelihoodOption); Option maxFindingsOption = Option.builder("maxFindings").hasArg(true).required(false).build(); commandLineOptions.addOption(maxFindingsOption); Option infoTypesOption = Option.builder("infoTypes").hasArg(true).required(false).build(); infoTypesOption.setArgs(Option.UNLIMITED_VALUES); commandLineOptions.addOption(infoTypesOption); Option includeQuoteOption = Option.builder("includeQuote").hasArg(true).required(false).build(); commandLineOptions.addOption(includeQuoteOption); Option bucketNameOption = Option.builder("bucketName").hasArg(true).required(false).build(); commandLineOptions.addOption(bucketNameOption); Option gcsFileNameOption = Option.builder("fileName").hasArg(true).required(false).build(); commandLineOptions.addOption(gcsFileNameOption); Option datasetIdOption = Option.builder("datasetId").hasArg(true).required(false).build(); commandLineOptions.addOption(datasetIdOption); Option tableIdOption = Option.builder("tableId").hasArg(true).required(false).build(); commandLineOptions.addOption(tableIdOption); Option projectIdOption = Option.builder("projectId").hasArg(true).required(false).build(); commandLineOptions.addOption(projectIdOption); Option datastoreNamespaceOption = Option.builder("namespace").hasArg(true).required(false).build(); commandLineOptions.addOption(datastoreNamespaceOption); Option datastoreKindOption = Option.builder("kind").hasArg(true).required(false).build(); commandLineOptions.addOption(datastoreKindOption); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(commandLineOptions, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp(Inspect.class.getName(), commandLineOptions); System.exit(1); return; } Likelihood minLikelihood = Likelihood.valueOf( cmd.getOptionValue(minLikelihoodOption.getOpt(), Likelihood.LIKELIHOOD_UNSPECIFIED.name())); int maxFindings = Integer.parseInt(cmd.getOptionValue(maxFindingsOption.getOpt(), "0")); boolean includeQuote = Boolean.parseBoolean(cmd.getOptionValue(includeQuoteOption.getOpt(), "true")); List<InfoType> infoTypesList = Collections.emptyList(); if (cmd.hasOption(infoTypesOption.getOpt())) { infoTypesList = new ArrayList<>(); String[] infoTypes = cmd.getOptionValues(infoTypesOption.getOpt()); for (String infoType : infoTypes) { infoTypesList.add(InfoType.newBuilder().setName(infoType).build()); } } // string inspection if (cmd.hasOption("s")) { String val = cmd.getOptionValue(stringOption.getOpt()); inspectString(val, minLikelihood, maxFindings, infoTypesList, includeQuote); } else if (cmd.hasOption("f")) { String filePath = cmd.getOptionValue(fileOption.getOpt()); inspectFile(filePath, minLikelihood, maxFindings, infoTypesList, includeQuote); // gcs file inspection } else if (cmd.hasOption("gcs")) { String bucketName = cmd.getOptionValue(bucketNameOption.getOpt()); String fileName = cmd.getOptionValue(gcsFileNameOption.getOpt()); inspectGcsFile(bucketName, fileName, minLikelihood, infoTypesList); // datastore kind inspection } else if (cmd.hasOption("ds")) { String namespaceId = cmd.getOptionValue(datastoreNamespaceOption.getOpt(), ""); String kind = cmd.getOptionValue(datastoreKindOption.getOpt()); // use default project id when project id is not specified String projectId = cmd.getOptionValue(projectIdOption.getOpt(), ServiceOptions.getDefaultProjectId()); inspectDatastore(projectId, namespaceId, kind, minLikelihood, infoTypesList); } else if (cmd.hasOption("bq")) { String datasetId = cmd.getOptionValue(datasetIdOption.getOpt()); String tableId = cmd.getOptionValue(tableIdOption.getOpt()); // use default project id when project id is not specified String projectId = cmd.getOptionValue(projectIdOption.getOpt(), ServiceOptions.getDefaultProjectId()); inspectBigquery(projectId, datasetId, tableId, minLikelihood, infoTypesList); } }
From source file:de.burlov.amazon.s3.dirsync.CLI.java
/** * @param args//from w w w .j a va2s.c o m */ @SuppressWarnings("static-access") public static void main(String[] args) { Logger.getLogger("").setLevel(Level.OFF); Logger deLogger = Logger.getLogger("de"); deLogger.setLevel(Level.INFO); Handler handler = new ConsoleHandler(); handler.setFormatter(new VerySimpleFormatter()); deLogger.addHandler(handler); deLogger.setUseParentHandlers(false); // if (true) // { // LogFactory.getLog(CLI.class).error("test msg", new Exception("test extception")); // return; // } Options opts = new Options(); OptionGroup gr = new OptionGroup(); /* * Befehlsgruppe initialisieren */ gr = new OptionGroup(); gr.setRequired(true); gr.addOption(OptionBuilder.withArgName("up|down").hasArg() .withDescription("Upload/Download changed or new files").create(CMD_UPDATE)); gr.addOption(OptionBuilder.withArgName("up|down").hasArg() .withDescription("Upload/Download directory snapshot").create(CMD_SNAPSHOT)); gr.addOption(OptionBuilder.withDescription("Delete remote folder").create(CMD_DELETE_DIR)); gr.addOption(OptionBuilder.withDescription("Delete a bucket").create(CMD_DELETE_BUCKET)); gr.addOption(OptionBuilder.create(CMD_HELP)); gr.addOption(OptionBuilder.create(CMD_VERSION)); gr.addOption(OptionBuilder.withDescription("Prints summary for stored data").create(CMD_SUMMARY)); gr.addOption(OptionBuilder.withDescription("Clean up orphaned objekts").create(CMD_CLEANUP)); gr.addOption(OptionBuilder.withDescription("Changes encryption password").withArgName("new password") .hasArg().create(CMD_CHANGE_PASSWORD)); gr.addOption(OptionBuilder.withDescription("Lists all buckets").create(CMD_LIST_BUCKETS)); gr.addOption(OptionBuilder.withDescription("Lists raw objects in a bucket").create(CMD_LIST_BUCKET)); gr.addOption(OptionBuilder.withDescription("Lists files in remote folder").create(CMD_LIST_DIR)); opts.addOptionGroup(gr); /* * Parametergruppe initialisieren */ opts.addOption(OptionBuilder.withArgName("key").isRequired(false).hasArg().withDescription("S3 access key") .create(OPT_S3S_KEY)); opts.addOption(OptionBuilder.withArgName("secret").isRequired(false).hasArg() .withDescription("Secret key for S3 account").create(OPT_S3S_SECRET)); opts.addOption(OptionBuilder.withArgName("bucket").isRequired(false).hasArg().withDescription( "Optional bucket name for storage. If not specified then an unique bucket name will be generated") .create(OPT_BUCKET)); // opts.addOption(OptionBuilder.withArgName("US|EU").hasArg(). // withDescription( // "Where the new bucket should be created. Default US").create( // OPT_LOCATION)); opts.addOption(OptionBuilder.withArgName("path").isRequired(false).hasArg() .withDescription("Local directory path").create(OPT_LOCAL_DIR)); opts.addOption(OptionBuilder.withArgName("name").isRequired(false).hasArg() .withDescription("Remote directory name").create(OPT_REMOTE_DIR)); opts.addOption(OptionBuilder.withArgName("password").isRequired(false).hasArg() .withDescription("Encryption password").create(OPT_ENC_PASSWORD)); opts.addOption(OptionBuilder.withArgName("patterns").hasArgs() .withDescription("Comma separated exclude file patterns like '*.tmp,*/dir/*.tmp'") .create(OPT_EXCLUDE_PATTERNS)); opts.addOption(OptionBuilder.withArgName("patterns").hasArgs().withDescription( "Comma separated include patterns like '*.java'. If not specified, then all files in specified local directory will be included") .create(OPT_INCLUDE_PATTERNS)); if (args.length == 0) { printUsage(opts); return; } CommandLine cmd = null; try { cmd = new GnuParser().parse(opts, args); if (cmd.hasOption(CMD_HELP)) { printUsage(opts); return; } if (cmd.hasOption(CMD_VERSION)) { System.out.println("s3dirsync version " + Version.CURRENT_VERSION); return; } String awsKey = cmd.getOptionValue(OPT_S3S_KEY); String awsSecret = cmd.getOptionValue(OPT_S3S_SECRET); String bucket = cmd.getOptionValue(OPT_BUCKET); String bucketLocation = cmd.getOptionValue(OPT_LOCATION); String localDir = cmd.getOptionValue(OPT_LOCAL_DIR); String remoteDir = cmd.getOptionValue(OPT_REMOTE_DIR); String password = cmd.getOptionValue(OPT_ENC_PASSWORD); String exclude = cmd.getOptionValue(OPT_EXCLUDE_PATTERNS); String include = cmd.getOptionValue(OPT_INCLUDE_PATTERNS); if (StringUtils.isBlank(awsKey) || StringUtils.isBlank(awsSecret)) { System.out.println("S3 account data required"); return; } if (StringUtils.isBlank(bucket)) { bucket = awsKey + ".dirsync"; } if (cmd.hasOption(CMD_DELETE_BUCKET)) { if (StringUtils.isBlank(bucket)) { System.out.println("Bucket name required"); return; } int deleted = S3Utils.deleteBucket(awsKey, awsSecret, bucket); System.out.println("Deleted objects: " + deleted); return; } if (cmd.hasOption(CMD_LIST_BUCKETS)) { for (String str : S3Utils.listBuckets(awsKey, awsSecret)) { System.out.println(str); } return; } if (cmd.hasOption(CMD_LIST_BUCKET)) { if (StringUtils.isBlank(bucket)) { System.out.println("Bucket name required"); return; } for (String str : S3Utils.listObjects(awsKey, awsSecret, bucket)) { System.out.println(str); } return; } if (StringUtils.isBlank(password)) { System.out.println("Encryption password required"); return; } char[] psw = password.toCharArray(); DirSync ds = new DirSync(awsKey, awsSecret, bucket, bucketLocation, psw); ds.setExcludePatterns(parseSubargumenths(exclude)); ds.setIncludePatterns(parseSubargumenths(include)); if (cmd.hasOption(CMD_SUMMARY)) { ds.printStorageSummary(); return; } if (StringUtils.isBlank(remoteDir)) { System.out.println("Remote directory name required"); return; } if (cmd.hasOption(CMD_DELETE_DIR)) { ds.deleteFolder(remoteDir); return; } if (cmd.hasOption(CMD_LIST_DIR)) { Folder folder = ds.getFolder(remoteDir); if (folder == null) { System.out.println("No such folder found: " + remoteDir); return; } for (Map.Entry<String, FileInfo> entry : folder.getIndexData().entrySet()) { System.out.println(entry.getKey() + " (" + FileUtils.byteCountToDisplaySize(entry.getValue().getLength()) + ")"); } return; } if (cmd.hasOption(CMD_CLEANUP)) { ds.cleanUp(); return; } if (cmd.hasOption(CMD_CHANGE_PASSWORD)) { String newPassword = cmd.getOptionValue(CMD_CHANGE_PASSWORD); if (StringUtils.isBlank(newPassword)) { System.out.println("new password required"); return; } char[] chars = newPassword.toCharArray(); ds.changePassword(chars); newPassword = null; Arrays.fill(chars, ' '); return; } if (StringUtils.isBlank(localDir)) { System.out.println(OPT_LOCAL_DIR + " argument required"); return; } String direction = ""; boolean up = false; boolean snapshot = false; if (StringUtils.isNotBlank(cmd.getOptionValue(CMD_UPDATE))) { direction = cmd.getOptionValue(CMD_UPDATE); } else if (StringUtils.isNotBlank(cmd.getOptionValue(CMD_SNAPSHOT))) { direction = cmd.getOptionValue(CMD_SNAPSHOT); snapshot = true; } if (StringUtils.isBlank(direction)) { System.out.println("Operation direction required"); return; } up = StringUtils.equalsIgnoreCase(OPT_UP, direction); File baseDir = new File(localDir); if (!baseDir.exists() && !baseDir.mkdirs()) { System.out.println("Invalid local directory: " + baseDir.getAbsolutePath()); return; } ds.syncFolder(baseDir, remoteDir, up, snapshot); } catch (DirSyncException e) { System.out.println(e.getMessage()); e.printStackTrace(); } catch (ParseException e) { System.out.println(e.getMessage()); printUsage(opts); } catch (Exception e) { e.printStackTrace(System.err); } }
From source file:it.unipd.dei.ims.falcon.CmdLine.java
public static void main(String[] args) { // last argument is always index path Options options = new Options(); // one of these actions has to be specified OptionGroup actionGroup = new OptionGroup(); actionGroup.addOption(new Option("i", true, "perform indexing")); // if dir, all files, else only one file actionGroup.addOption(new Option("q", true, "perform a single query")); actionGroup.addOption(new Option("b", false, "perform a query batch (read from stdin)")); actionGroup.setRequired(true); options.addOptionGroup(actionGroup); // other options options.addOption(new Option("l", "segment-length", true, "length of a segment (# of chroma vectors)")); options.addOption(/*from w w w. j a v a 2 s . co m*/ new Option("o", "segment-overlap", true, "overlap portion of a segment (# of chroma vectors)")); options.addOption(new Option("Q", "quantization-level", true, "quantization level for chroma vectors")); options.addOption(new Option("k", "min-kurtosis", true, "minimum kurtosis for indexing chroma vectors")); options.addOption(new Option("s", "sub-sampling", true, "sub-sampling of chroma features")); options.addOption(new Option("v", "verbose", false, "verbose output (including timing info)")); options.addOption(new Option("T", "transposition-estimator-strategy", true, "parametrization for the transposition estimator strategy")); options.addOption(new Option("t", "n-transp", true, "number of transposition; if not specified, no transposition is performed")); options.addOption(new Option("f", "force-transp", true, "force transposition by an amount of semitones")); options.addOption(new Option("p", "pruning", false, "enable query pruning; if -P is unspecified, use default strategy")); options.addOption(new Option("P", "pruning-custom", true, "custom query pruning strategy")); // parse HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length != 1) throw new ParseException("no index path was specified"); } catch (ParseException ex) { System.err.println("ERROR - parsing command line:"); System.err.println(ex.getMessage()); formatter.printHelp("falcon -{i,q,b} [options] index_path", options); return; } // default values final float[] DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY = new float[] { 0.65192807f, 0.0f, 0.0f, 0.0f, 0.3532628f, 0.4997167f, 0.0f, 0.41703504f, 0.0f, 0.16297342f, 0.0f, 0.0f }; final String DEFAULT_QUERY_PRUNING_STRATEGY = "ntf:0.340765*[0.001694,0.995720];ndf:0.344143*[0.007224,0.997113];" + "ncf:0.338766*[0.001601,0.995038];nmf:0.331577*[0.002352,0.997884];"; // TODO not the final one int hashes_per_segment = Integer.parseInt(cmd.getOptionValue("l", "150")); int overlap_per_segment = Integer.parseInt(cmd.getOptionValue("o", "50")); int nranks = Integer.parseInt(cmd.getOptionValue("Q", "3")); int subsampling = Integer.parseInt(cmd.getOptionValue("s", "1")); double minkurtosis = Float.parseFloat(cmd.getOptionValue("k", "-100.")); boolean verbose = cmd.hasOption("v"); int ntransp = Integer.parseInt(cmd.getOptionValue("t", "1")); TranspositionEstimator tpe = null; if (cmd.hasOption("t")) { if (cmd.hasOption("T")) { // TODO this if branch is yet to test Pattern p = Pattern.compile("\\d\\.\\d*"); LinkedList<Double> tokens = new LinkedList<Double>(); Matcher m = p.matcher(cmd.getOptionValue("T")); while (m.find()) tokens.addLast(new Double(cmd.getOptionValue("T").substring(m.start(), m.end()))); float[] strategy = new float[tokens.size()]; if (strategy.length != 12) { System.err.println("invalid transposition estimator strategy"); System.exit(1); } for (int i = 0; i < strategy.length; i++) strategy[i] = new Float(tokens.pollFirst()); } else { tpe = new TranspositionEstimator(DEFAULT_TRANSPOSITION_ESTIMATOR_STRATEGY); } } else if (cmd.hasOption("f")) { int[] transps = parseIntArray(cmd.getOptionValue("f")); tpe = new ForcedTranspositionEstimator(transps); ntransp = transps.length; } QueryPruningStrategy qpe = null; if (cmd.hasOption("p")) { if (cmd.hasOption("P")) { qpe = new StaticQueryPruningStrategy(cmd.getOptionValue("P")); } else { qpe = new StaticQueryPruningStrategy(DEFAULT_QUERY_PRUNING_STRATEGY); } } // action if (cmd.hasOption("i")) { try { Indexing.index(new File(cmd.getOptionValue("i")), new File(cmd.getArgs()[0]), hashes_per_segment, overlap_per_segment, subsampling, nranks, minkurtosis, tpe, verbose); } catch (IndexingException ex) { Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex); } } if (cmd.hasOption("q")) { String queryfilepath = cmd.getOptionValue("q"); doQuery(cmd, queryfilepath, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp, minkurtosis, qpe, verbose); } if (cmd.hasOption("b")) { try { long starttime = System.currentTimeMillis(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String line = null; while ((line = in.readLine()) != null && !line.trim().isEmpty()) doQuery(cmd, line, hashes_per_segment, overlap_per_segment, nranks, subsampling, tpe, ntransp, minkurtosis, qpe, verbose); in.close(); long endtime = System.currentTimeMillis(); System.out.println(String.format("total time: %ds", (endtime - starttime) / 1000)); } catch (IOException ex) { Logger.getLogger(CmdLine.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:edu.cornell.med.icb.R.RUtils.java
public static void main(final String[] args) throws ParseException, ConfigurationException { final Options options = new Options(); final Option helpOption = new Option("h", "help", false, "Print this message"); options.addOption(helpOption);// ww w . j av a2s .co m final Option startupOption = new Option(Mode.startup.name(), Mode.startup.name(), false, "Start Rserve process"); final Option shutdownOption = new Option(Mode.shutdown.name(), Mode.shutdown.name(), false, "Shutdown Rserve process"); final Option validateOption = new Option(Mode.validate.name(), Mode.validate.name(), false, "Validate that Rserve processes are running"); final OptionGroup optionGroup = new OptionGroup(); optionGroup.addOption(startupOption); optionGroup.addOption(shutdownOption); optionGroup.addOption(validateOption); optionGroup.setRequired(true); options.addOptionGroup(optionGroup); final Option portOption = new Option("port", "port", true, "Use specified port to communicate with the Rserve process"); portOption.setArgName("port"); portOption.setType(int.class); options.addOption(portOption); final Option hostOption = new Option("host", "host", true, "Communicate with the Rserve process on the given host"); hostOption.setArgName("hostname"); hostOption.setType(String.class); options.addOption(hostOption); final Option userOption = new Option("u", "username", true, "Username to send to the Rserve process"); userOption.setArgName("username"); userOption.setType(String.class); options.addOption(userOption); final Option passwordOption = new Option("p", "password", true, "Password to send to the Rserve process"); passwordOption.setArgName("password"); passwordOption.setType(String.class); options.addOption(passwordOption); final Option configurationOption = new Option("c", "configuration", true, "Configuration file or url to read from"); configurationOption.setArgName("configuration"); configurationOption.setType(String.class); options.addOption(configurationOption); final Parser parser = new BasicParser(); final CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException e) { usage(options); throw e; } int exitStatus = 0; if (commandLine.hasOption("h")) { usage(options); } else { Mode mode = null; for (final Mode potentialMode : Mode.values()) { if (commandLine.hasOption(potentialMode.name())) { mode = potentialMode; break; } } final ExecutorService threadPool = Executors.newCachedThreadPool(); if (commandLine.hasOption("configuration")) { final String configurationFile = commandLine.getOptionValue("configuration"); LOG.info("Reading configuration from " + configurationFile); XMLConfiguration configuration; try { final URL configurationURL = new URL(configurationFile); configuration = new XMLConfiguration(configurationURL); } catch (MalformedURLException e) { // resource is not a URL: attempt to get the resource from a file LOG.debug("Configuration is not a valid url"); configuration = new XMLConfiguration(configurationFile); } configuration.setValidating(true); final int numberOfRServers = configuration.getMaxIndex("RConfiguration.RServer") + 1; boolean failed = false; for (int i = 0; i < numberOfRServers; i++) { final String server = "RConfiguration.RServer(" + i + ")"; final String host = configuration.getString(server + "[@host]"); final int port = configuration.getInt(server + "[@port]", RConfigurationUtils.DEFAULT_RSERVE_PORT); final String username = configuration.getString(server + "[@username]"); final String password = configuration.getString(server + "[@password]"); final String command = configuration.getString(server + "[@command]", DEFAULT_RSERVE_COMMAND); if (executeMode(mode, threadPool, host, port, username, password, command) != 0) { failed = true; // we have other hosts to check so keep a failed state } } if (failed) { exitStatus = 3; } } else { final String host = commandLine.getOptionValue("host", "localhost"); final int port = Integer.valueOf(commandLine.getOptionValue("port", "6311")); final String username = commandLine.getOptionValue("username"); final String password = commandLine.getOptionValue("password"); exitStatus = executeMode(mode, threadPool, host, port, username, password, null); } threadPool.shutdown(); } System.exit(exitStatus); }
From source file:com.hurence.logisland.plugin.PluginManager.java
public static void main(String... args) throws Exception { System.out.println(BannerLoader.loadBanner()); String logislandHome = new File( new File(PluginManager.class.getProtectionDomain().getCodeSource().getLocation().getPath()) .getParent()).getParent(); System.out.println("Using Logisland home: " + logislandHome); Options options = new Options(); OptionGroup mainGroup = new OptionGroup() .addOption(OptionBuilder.withDescription( "Install a component. It can be either a logisland plugin or a kafka connect module.") .withArgName("artifact").hasArgs(1).withLongOpt("install").create("i")) .addOption(OptionBuilder.withDescription( "Removes a component. It can be either a logisland plugin or a kafka connect module.") .withArgName("artifact").hasArgs(1).withLongOpt("remove").create("r")) .addOption(OptionBuilder.withDescription("List installed components.").withLongOpt("list") .create("l")); mainGroup.setRequired(true); options.addOptionGroup(mainGroup);/*from w ww . ja va 2 s. c o m*/ options.addOption(OptionBuilder.withDescription("Print this help.").withLongOpt("help").create("h")); try { CommandLine commandLine = new PosixParser().parse(options, args); System.out.println(commandLine.getArgList()); if (commandLine.hasOption("l")) { listPlugins(); } else if (commandLine.hasOption("i")) { installPlugin(commandLine.getOptionValue("i"), logislandHome); } else if (commandLine.hasOption("r")) { removePlugin(commandLine.getOptionValue("r")); } else { printUsage(options); } } catch (ParseException e) { if (!options.hasOption("h")) { System.err.println(e.getMessage()); System.out.println(); } printUsage(options); } }
From source file:LNISmokeTest.java
/** * Execute command line. See Usage string for options and arguments. * //from w w w. ja v a 2 s .co m * @param argv the argv * * @throws Exception the exception */ public static void main(String[] argv) throws Exception { Options options = new Options(); OptionGroup func = new OptionGroup(); func.addOption(new Option("c", "copy", true, "copy <Item> to -C <Collection>")); func.addOption(new Option("s", "submit", true, "submit <collection> -P <packager> -i <file>")); func.addOption(new Option("d", "disseminate", true, "disseminate <item> -P <packager> -o <file>")); func.addOption(new Option("f", "propfind", true, "propfind of all properties or -N <propname>")); func.addOption(new Option("r", "rpropfind", true, "recursive propfind, only collections")); func.addOption(new Option("n", "names", true, "list all property names on resource")); func.addOption(new Option("p", "proppatch", true, "set property: <handle> -N <property> -V <newvalue>")); func.setRequired(true); options.addOptionGroup(func); options.addOption("h", "help", false, "show help message"); options.addOption("e", "endpoint", true, "SOAP endpoint URL (REQUIRED)"); options.addOption("P", "packager", true, "Packager to use to import/export a package."); options.addOption("C", "collection", true, "Target collection of -c copy"); options.addOption("o", "output", true, "file to create for new package"); options.addOption("i", "input", true, "file containing package to submit"); options.addOption("N", "name", true, "name of property to query/set"); options.addOption("V", "value", true, "new value for property being set"); try { CommandLine line = (new PosixParser()).parse(options, argv); if (line.hasOption("h")) { usage(options, 0, null); } // get SOAP client connection, using the endpoint URL String endpoint = line.getOptionValue("e"); if (endpoint == null) { usage(options, 2, "Missing the required -e endpoint argument"); } LNISoapServletServiceLocator loc = new LNISoapServletServiceLocator(); LNISoapServlet lni = loc.getDSpaceLNI(new URL(endpoint)); // propfind - with optional single-property Name if (line.hasOption("f")) { String pfXml = (line.hasOption("N")) ? specificPropPrefix + line.getOptionValue("N") + specificPropSuffix : allProp; doPropfind(lni, line.getOptionValue("f"), pfXml, 0, null); } // recursive propfind limited to collection, community objects else if (line.hasOption("r")) { doPropfind(lni, line.getOptionValue("r"), someProp, -1, "collection,community"); } else if (line.hasOption("n")) { doPropfind(lni, line.getOptionValue("n"), nameProp, 0, null); } else if (line.hasOption("p")) { if (line.hasOption("N") && line.hasOption("V")) { doProppatch(lni, line.getOptionValue("p"), line.getOptionValue("N"), line.getOptionValue("V")); } else { usage(options, 13, "Missing required args: -N <name> -V <value>n"); } } // submit a package else if (line.hasOption("s")) { if (line.hasOption("P") && line.hasOption("i")) { doPut(lni, line.getOptionValue("s"), line.getOptionValue("P"), line.getOptionValue("i"), endpoint); } else { usage(options, 13, "Missing required args after -s: -P <packager> -i <file>"); } } // Disseminate (GET) item as package else if (line.hasOption("d")) { if (line.hasOption("P") && line.hasOption("o")) { doGet(lni, line.getOptionValue("d"), line.getOptionValue("P"), line.getOptionValue("o"), endpoint); } else { usage(options, 13, "Missing required args after -d: -P <packager> -o <file>"); } } // copy from src to dst else if (line.hasOption("c")) { if (line.hasOption("C")) { doCopy(lni, line.getOptionValue("c"), line.getOptionValue("C")); } else { usage(options, 13, "Missing required args after -c: -C <collection>\n"); } } else { usage(options, 14, "Missing command option.\n"); } } catch (ParseException pe) { usage(options, 1, "Error in arguments: " + pe.toString()); } catch (java.rmi.RemoteException de) { System.out.println("ERROR, got RemoteException, message=" + de.getMessage()); de.printStackTrace(); die(1, " Exception class=" + de.getClass().getName()); } }
From source file:com.falcon.orca.helpers.CommandHelper.java
public static Options createOptions() { Option start = Option.builder("s").longOpt("start").build(); Option stop = Option.builder("st").longOpt("stop").build(); Option pause = Option.builder("p").longOpt("pause").build(); Option continueOpt = Option.builder("re").longOpt("resume").build(); Option exit = Option.builder("e").longOpt("exit").build(); Option url = Option.builder("U").longOpt("url").hasArg(true).build(); Option durationMode = Option.builder("DM").longOpt("durationMode").hasArg(true).build(); Option duration = Option.builder("DU").longOpt("duration").hasArg(true).build(); Option repeats = Option.builder("R").longOpt("repeats").hasArg(true).build(); Option method = Option.builder("M").longOpt("method").hasArg(true).build(); Option header = Option.builder("H").longOpt("header").hasArg(true).build(); Option concurrency = Option.builder("C").longOpt("concurrency").hasArg(true).build(); Option templateFile = Option.builder("TF").longOpt("template").hasArg(true).build(); Option dataFile = Option.builder("DF").longOpt("dataFile").hasArg(true).build(); Option cookies = Option.builder("CO").longOpt("cookie").hasArg(true).build(); Option data = Option.builder("D").longOpt("data").hasArg(true).type(String.class).build(); OptionGroup optionGroup = new OptionGroup(); optionGroup.setRequired(true); optionGroup.addOption(start);//from w w w .j a v a 2 s . c o m optionGroup.addOption(stop); optionGroup.addOption(pause); optionGroup.addOption(continueOpt); optionGroup.addOption(exit); Options options = new Options(); options.addOptionGroup(optionGroup); options.addOption(url); options.addOption(durationMode); options.addOption(duration); options.addOption(repeats); options.addOption(method); options.addOption(header); options.addOption(concurrency); options.addOption(cookies); options.addOption(data); options.addOption(templateFile); options.addOption(dataFile); return options; }
From source file:com.nokia.tools.vct.cli.CommandLineUtils.java
public static void initOptions(Options options) { IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtension[] extensions = registry.getExtensionPoint(EXTENSION_NAMESPACE).getExtensions(); for (IExtension extension : extensions) { for (IConfigurationElement element : extension.getConfigurationElements()) { if (ELEMENT_OPTION.equals(element.getName())) { Option option = makeOption(element); options.addOption(option); } else if (ELEMENT_OPTION_GROUP.equals(element.getName())) { OptionGroup optionGroup = new OptionGroup(); boolean required = Boolean.TRUE.equals(element.getAttribute(OPTION_GROUP_ATTR_REQUIRED)); optionGroup.setRequired(required); for (IConfigurationElement element2 : element.getChildren(ELEMENT_OPTION)) { Option option = makeOption(element2); optionGroup.addOption(option); }/*from ww w . j av a 2s. c om*/ options.addOptionGroup(optionGroup); } } } }