List of usage examples for org.apache.commons.cli CommandLine getArgList
public List getArgList()
From source file:net.bpelunit.framework.ui.command.BPELUnitCommandLineRunner.java
@SuppressWarnings("unchecked") private final void parseOptionsFromCommandLine(String[] args) { saveCoverageDetails = false;/* ww w . ja v a 2 s . co m*/ CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); verifyCommandLineArguments(cmd); verbose = cmd.hasOption(PARAMETER_VERBOSE); xmlFileName = trimEqualsSignFromStart(cmd.getOptionValue(PARAMETER_XMLFILE)); logFileName = trimEqualsSignFromStart(cmd.getOptionValue(PARAMETER_LOGFILE)); ArrayList<String> remainingOptions = new ArrayList<String>(cmd.getArgList()); setAndValidateTestSuiteFileName(remainingOptions.remove(0)); testCaseNames = remainingOptions; } catch (ParseException e) { showHelpAndExit(); } }
From source file:com.ery.estorm.daemon.EMasterCommandLine.java
public int run(String args[]) throws Exception { Options opt = new Options();// ?? --param opt.addOption("debug", true, "debug type");// EStormConstant.DebugType CommandLine cmd; try {// w ww .j a v a2s. c om cmd = new GnuParser().parse(opt, args); } catch (ParseException e) { LOG.error("Could not parse: ", e); usage(null); return 1; } // if (test() > 0) // return 1; String debug = cmd.getOptionValue("debug"); if (debug != null) { EStormConstant.DebugType = Integer.parseInt(debug); } List<String> remainingArgs = cmd.getArgList(); if (remainingArgs.size() < 1) { usage(null); return 1; } String command = remainingArgs.get(0); if ("start".equals(command)) { return startMaster(); } else if ("stop".equals(command)) { return stopMaster(); } else if ("stopCluster".equals(command)) { return stopCluster(); } else { usage("Invalid command: " + command); return 1; } }
From source file:net.bpelunit.framework.ui.command.BPELUnitCommandLineRunner.java
private void verifyCommandLineArguments(CommandLine cmd) { if (cmd.hasOption(PARAMETER_COVERAGEFILE) && cmd.hasOption(PARAMETER_DETAILEDCOVERAGEFILE)) { abort(String.format(/*w w w . ja va 2 s .c o m*/ Messages.getString( "BPELUnitCommandLineRunner.MSG_ERR_PARAMETER_COVERAGE_DETAILEDCOVERAGE_ARE_EXCLUSIVE"), //$NON-NLS-1$ PARAMETER_COVERAGEFILE, PARAMETER_DETAILEDCOVERAGEFILE)); } if (cmd.getArgList().size() == 0) { showHelpAndExit(); } }
From source file:com.netcrest.pado.tools.pado.command.put.java
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override//from w ww.java2 s . c om public void run(CommandLine commandLine, String command) throws Exception { String path = commandLine.getOptionValue("path"); String bufferName = commandLine.getOptionValue("buffer"); List<String> argList = commandLine.getArgList(); if (path != null && bufferName != null) { PadoShell.printlnError(this, "Specifying both path and buffer not allowed. Only one option allowed."); return; } if (argList.size() < 2) { PadoShell.println(this, "Must specify key/value pair(s)."); return; } if (path == null && bufferName == null) { path = padoShell.getCurrentPath(); } boolean keyEnumerated = commandLine.hasOption('k'); boolean valueEnumerated = commandLine.hasOption('v'); Option options[] = commandLine.getOptions(); for (Option option : options) { if (keyEnumerated == false) { keyEnumerated = option.getOpt().contains("k"); } if (valueEnumerated == false) { valueEnumerated = option.getOpt().contains("v"); } } int keyIndex = argList.indexOf(argList.get(1)); String fullPath; String gridId; String gridPath; BufferInfo bufferInfo = null; if (path != null) { fullPath = padoShell.getFullPath(path); gridPath = GridUtil.getChildPath(fullPath); gridId = SharedCache.getSharedCache().getGridId(fullPath); } else { bufferInfo = SharedCache.getSharedCache().getBufferInfo(bufferName); if (bufferInfo == null) { PadoShell.printlnError(this, bufferName + ": Buffer undefined."); return; } gridId = bufferInfo.getGridId(); gridPath = bufferInfo.getGridPath(); if (gridId == null || gridPath == null) { PadoShell.printlnError(this, bufferName + ": Invalid buffer. This buffer does not contain keys."); return; } fullPath = SharedCache.getSharedCache().getPado().getCatalog().getGridService().getFullPath(gridId, gridPath); } Map map = getEntryMap(fullPath, bufferInfo, argList, keyEnumerated, valueEnumerated, keyIndex); IGridMapBiz gridMapBiz = SharedCache.getSharedCache().getPado().getCatalog().newInstance(IGridMapBiz.class, gridPath); gridMapBiz.getBizContext().getGridContextClient().setGridIds(gridId); gridMapBiz.putAll(map); // ArrayList keyList = new ArrayList(); if (padoShell.isShowResults()) { PrintUtil.printEntries(gridMapBiz, map.keySet(), null); } }
From source file:com.marklogic.shell.command.cp.java
public void execute(Environment env, String commandline) { if (commandline != null && commandline.length() > 0) { String[] tokens = commandline.split("\\s+"); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try {//from w w w . j a v a2s .co m cmd = parser.parse(options, tokens); } catch (ParseException e) { env.outputException(e); return; } boolean force = cmd.hasOption("f"); String fromHost = cmd.getOptionValue("s"); String toHost = cmd.getOptionValue("d"); if ((fromHost != null && fromHost.length() > 0) || (toHost != null && fromHost.length() > 0)) { env.outputLine("Copying from or to remote hosts is not implmented yet"); } else { if (cmd.getArgList().size() == 2) { String source = cmd.getArgList().get(0).toString(); String destination = cmd.getArgList().get(1).toString(); String query = null; if (force) { query = "if(doc('" + source + "')) then xdmp:document-insert('" + destination + "', doc('" + source + "')) " + "else \"Source document not found.\""; } else { query = "if(doc('" + source + "') and not(doc('" + destination + "'))) then xdmp:document-insert('" + destination + "', doc('" + source + "')) " + "else \"Source document not found or target document exists.\""; } Session session = env.getContentSource().newSession(); AdhocQuery request = session.newAdhocQuery(query); try { env.outputResultSequence(session.submitRequest(request)); } catch (RequestException e) { env.outputException(e); } } else { if (cmd.getArgList().size() == 1) { env.outputLine("Missing target document uri"); } else if (cmd.getArgList().size() == 0) { env.outputLine("Missing source and target document uri"); } else { env.outputLine("Too many arguments"); } } } } else { env.outputLine("Please specify document to copy. See help cp."); } }
From source file:com.nokia.tools.variant.carbidev.CarbideRCPHandler.java
public void handleCommandLine(CommandLine commandLine, Options options) throws StopException { if (commandLine.getOptions().length != 0) { return;/* ww w .j a va2 s . co m*/ } boolean binded = CarbideVRemote.bind(); if (!binded) { // wait till remote carbidev is ready, but max. 10 second :-) int retry = 10; while (CarbideVRemote.getRemote() == null && retry > 0) { try { Thread.sleep(1000); } catch (InterruptedException ie) { } retry--; } if (CarbideVRemote.getRemote() != null) { handleOpenedCarbide(commandLine.getArgList()); throw new StopException(IApplication.EXIT_OK); } } Display display = PlatformUI.createDisplay(); try { int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) throw new StopException(IApplication.EXIT_RESTART); else throw new StopException(IApplication.EXIT_OK); } finally { display.dispose(); } }
From source file:com.rockstor.tools.RockStorFsFormat.java
@Override public int run(String[] args) { Options opt = new Options(); opt.addOption("useOldSplits", false, "truncate htable, and split it by the old splits"); opt.addOption("clean", false, "only clean system!"); CommandLine cmd; try {/*from ww w .ja v a2 s. com*/ cmd = new GnuParser().parse(opt, args); } catch (ParseException e) { LOG.error("Could not parse: ", e); usage(null); return -1; } if (cmd.hasOption("clean")) { this.onlyClean = true; } else if (cmd.hasOption("useOldSplits")) { followOldSplit = true; LOG.debug("useOldSplits set to " + followOldSplit); } if (cmd.getArgList().size() > 0) { usage(null); return -1; } try { System.out.println(RockConfiguration.str(hbaseConf)); ha = new HBaseAdmin(hbaseConf); cleanDfs(); cleanDB(); if (!this.onlyClean) { initDfs(); createDB(); } close(); } catch (IOException e) { e.printStackTrace(); return -1; } return 0; }
From source file:VOConfig.java
/** * Set configuration by parsed commandline options. * * @param cmd parsed commandline options *//*from w ww. j a v a2s . c o m*/ public void setCmd(CommandLine cmd) { if (cmd.hasOption("repository")) { this.repository = cmd.getOptionValue("repository"); } if (cmd.hasOption("backup")) { this.backup = cmd.getOptionValue("backup"); } if (cmd.hasOption("exclude")) { this.exclude = new ArrayList<>(); this.exclude.addAll(Arrays.asList(cmd.getOptionValues("exclude"))); } if (cmd.hasOption("exclude-dir")) { this.excludedir = new ArrayList<>(); this.excludedir.addAll(Arrays.asList(cmd.getOptionValues("exclude-dir"))); } if (CollectionUtils.isNotEmpty(cmd.getArgList())) { //noinspection unchecked this.paths = new ArrayList<String>(cmd.getArgList()); } }
From source file:DcmSnd.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("aet[@host][:port]"); OptionBuilder.hasArg();//from w ww .j av a 2s .c o m OptionBuilder.withDescription("set AET, local address and listening port of local Application Entity"); opts.addOption(OptionBuilder.create("L")); opts.addOption("ts1", false, "offer Default Transfer Syntax in " + "separate Presentation Context. By default offered with\n" + "Explicit VR Little Endian TS in one PC."); opts.addOption("fileref", false, "send objects without pixel data, but with a reference to " + "the DICOM file using DCM4CHE URI\nReferenced Transfer Syntax " + "to import DICOM objects\n on a given file system to a DCM4CHEE " + "archive."); OptionBuilder.withArgName("username"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "enable User Identity Negotiation with specified username and " + " optional passcode"); opts.addOption(OptionBuilder.create("username")); OptionBuilder.withArgName("passcode"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "optional passcode for User Identity Negotiation, " + "only effective with option -username"); opts.addOption(OptionBuilder.create("passcode")); opts.addOption("uidnegrsp", false, "request positive User Identity Negotation response, " + "only effective with option -username"); OptionBuilder.withArgName("NULL|3DES|AES"); OptionBuilder.hasArg(); OptionBuilder.withDescription("enable TLS connection without, 3DES or AES encryption"); opts.addOption(OptionBuilder.create("tls")); opts.addOption("nossl2", false, "disable acceptance of SSLv2Hello TLS handshake"); opts.addOption("noclientauth", false, "disable client authentification for TLS"); OptionBuilder.withArgName("file|url"); OptionBuilder.hasArg(); OptionBuilder .withDescription("file path or URL of P12 or JKS keystore, resource:tls/test_sys_2.p12 by default"); opts.addOption(OptionBuilder.create("keystore")); OptionBuilder.withArgName("password"); OptionBuilder.hasArg(); OptionBuilder.withDescription("password for keystore file, 'secret' by default"); opts.addOption(OptionBuilder.create("keystorepw")); OptionBuilder.withArgName("password"); OptionBuilder.hasArg(); OptionBuilder .withDescription("password for accessing the key in the keystore, keystore password by default"); opts.addOption(OptionBuilder.create("keypw")); OptionBuilder.withArgName("file|url"); OptionBuilder.hasArg(); OptionBuilder.withDescription("file path or URL of JKS truststore, resource:tls/mesa_certs.jks by default"); opts.addOption(OptionBuilder.create("truststore")); OptionBuilder.withArgName("password"); OptionBuilder.hasArg(); OptionBuilder.withDescription("password for truststore file, 'secret' by default"); opts.addOption(OptionBuilder.create("truststorepw")); OptionBuilder.withArgName("aet@host:port"); OptionBuilder.hasArg(); OptionBuilder.withDescription("request storage commitment of (successfully) sent objects " + "afterwards in new association\nto specified remote " + "Application Entity"); opts.addOption(OptionBuilder.create("stgcmtae")); opts.addOption("stgcmt", false, "request storage commitment of (successfully) sent objects " + "afterwards in same association"); OptionBuilder.withArgName("maxops"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximum number of outstanding operations it may invoke " + "asynchronously, unlimited by default."); opts.addOption(OptionBuilder.create("async")); opts.addOption("pdv1", false, "send only one PDV in one P-Data-TF PDU, " + "pack command and data PDV in one P-DATA-TF PDU by default."); opts.addOption("tcpdelay", false, "set TCP_NODELAY socket option to false, true by default"); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("timeout in ms for TCP connect, no timeout by default"); opts.addOption(OptionBuilder.create("connectTO")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("delay in ms for Socket close after sending A-ABORT, " + "50ms by default"); opts.addOption(OptionBuilder.create("soclosedelay")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("delay in ms for closing the listening socket, " + "1000ms by default"); opts.addOption(OptionBuilder.create("shutdowndelay")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("period in ms to check for outstanding DIMSE-RSP, " + "10s by default"); opts.addOption(OptionBuilder.create("reaper")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("timeout in ms for receiving DIMSE-RSP, 60s by default"); opts.addOption(OptionBuilder.create("rspTO")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("timeout in ms for receiving A-ASSOCIATE-AC, 5s by default"); opts.addOption(OptionBuilder.create("acceptTO")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("timeout in ms for receiving A-RELEASE-RP, 5s by default"); opts.addOption(OptionBuilder.create("releaseTO")); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximal length in KB of received P-DATA-TF PDUs, 16KB by default"); opts.addOption(OptionBuilder.create("rcvpdulen")); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximal length in KB of sent P-DATA-TF PDUs, 16KB by default"); opts.addOption(OptionBuilder.create("sndpdulen")); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("set SO_RCVBUF socket option to specified value in KB"); opts.addOption(OptionBuilder.create("sorcvbuf")); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("set SO_SNDBUF socket option to specified value in KB"); opts.addOption(OptionBuilder.create("sosndbuf")); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("transcoder buffer size in KB, 1KB by default"); opts.addOption(OptionBuilder.create("bufsize")); opts.addOption("lowprior", false, "LOW priority of the C-STORE operation, MEDIUM by default"); opts.addOption("highprior", false, "HIGH priority of the C-STORE operation, MEDIUM by default"); opts.addOption("h", "help", false, "print this message"); opts.addOption("V", "version", false, "print the version information and exit"); CommandLine cl = null; try { cl = new GnuParser().parse(opts, args); } catch (ParseException e) { exit("dcmsnd: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = DcmSnd.class.getPackage(); System.out.println("dcmsnd v" + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption('h') || cl.getArgList().size() < 2) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE); System.exit(0); } return cl; }
From source file:com.rockstor.tools.CompactorTool.java
@Override public int run(String[] args) throws Exception { Options opt = new Options(); opt.addOption("op", false, "which operation to do"); CommandLine cmd; String opType = "all"; try {// w ww .java2 s .c o m cmd = new GnuParser().parse(opt, args); } catch (ParseException e) { LOG.error("Could not parse: ", e); usage(null); return -1; } if (cmd.hasOption("op")) { opType = cmd.getOptionValue("op", opType); LOG.debug("opType set to " + opType); } BaseOp op = opMap.get(opType); if (cmd.getArgList().size() > 0 || op == null) { usage("unknown op type: " + opType); return -1; } return op.exec(); }