List of usage examples for org.apache.commons.cli CommandLine getArgList
public List getArgList()
From source file:eu.sonata.nfv.nec.validate.cli.Main.java
/** * Parses the command line arguments.//from w ww . j av a2 s . c om * * @param args The command line arguments. */ private static void parseCliOptions(String[] args) { // Command line options. Options options = createCliOptions(); // Command line parser. CommandLineParser parser = new DefaultParser(); try { // Parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("h")) { printHelp(options); System.exit(EXIT_CODE_SUCCESS); } if (line.hasOption("s")) { schemaFile = normalizePath(line.getOptionValue('s')); if (schemaFile == null) checkSchema = false; } if (line.hasOption("v")) { setLogLevel(2); } if (line.hasOption("d")) { checkSchema = false; } if (line.hasOption("c")) { coloredOutput = true; } if (line.hasOption("k")) { schemaKey = line.getOptionValue('k'); } else { schemaKey = DEFAULT_SCHEMA_KEY; } // Get whatever ist left, after the options have been processed. if (line.getArgList() == null || line.getArgList().isEmpty()) { throw new MissingArgumentException("JSON/YAML file to validate is missing."); } else { jsonFile = normalizePath(line.getArgList().get(0)); } } catch (MissingOptionException | MissingArgumentException e) { System.err.println("ERROR: " + e.getMessage() + "\n"); printHelp(options); System.exit(EXIT_CODE_ERROR); } catch (ParseException e) { // Oops, something went wrong System.err.println("ERROR: Parsing failed. Reason: " + e.getMessage()); } }
From source file:com.netcrest.pado.tools.pado.command.ls.java
@Override public void run(CommandLine commandLine, String command) throws Exception { String path;/*from ww w .ja va 2s. c o m*/ if (commandLine.getArgList().size() == 1) { path = padoShell.getCurrentPath(); } else { path = (String) commandLine.getArgList().get(1); } boolean includeHidden = commandLine.hasOption("a"); boolean longList = commandLine.hasOption("l"); boolean recursive = commandLine.hasOption("R"); Option options[] = commandLine.getOptions(); for (Option option : options) { if (includeHidden == false) { includeHidden = option.getOpt().contains("a"); } if (longList == false) { longList = option.getOpt().contains("l"); } if (recursive == false) { recursive = option.getOpt().contains("R"); } } listPaths(path, includeHidden, longList, recursive); }
From source file:fr.inrialpes.exmo.align.cli.CommonCLI.java
public void parseSpecificCommandLine(String[] args) { try {/*from w w w. ja v a 2 s .c o m*/ CommandLine line = parseCommandLine(args); if (line == null) return; // Here deal with command specific arguments for (Object o : line.getArgList()) { logger.info(" Arg: {}", o); } for (Entry<Object, Object> m : parameters.entrySet()) { logger.info(" Param: {} = {}", m.getKey(), m.getValue()); } } catch (ParseException exp) { logger.error(exp.getMessage()); usage(); } }
From source file:com.netcrest.pado.tools.pado.command.mkpath.java
@SuppressWarnings({ "unchecked" }) private void handlePathType(CommandLine commandLine) { List<String> argList = commandLine.getArgList(); boolean recursive = PadoShellUtil.hasSingleLetterOption(commandLine, 'p', excludes); boolean verbose = PadoShellUtil.hasSingleLetterOption(commandLine, 'v', excludes); String type = commandLine.getOptionValue("type"); String diskStoreName = commandLine.getOptionValue("diskStoreName"); int numBuckets = 113; String colocatedWith = null;//from www .j a va 2 s . c o m int redundantCopies = 1; String value = commandLine.getOptionValue("buckets"); if (value != null) { numBuckets = Integer.parseInt(value); } colocatedWith = commandLine.getOptionValue("colocatedWith"); value = commandLine.getOptionValue("redundantCopies"); if (value != null) { redundantCopies = Integer.parseInt(value); } // Determine the path type PathType pathType; if (type == null) { pathType = PathType.TEMPORAL; } else { pathType = PathType.valueOf(type.toUpperCase()); } if (pathType == null) { pathType = PathType.TEMPORAL; } String gatewaySenderIds = commandLine.getOptionValue("gatewaySenderIds"); // Create path(s) List<String> fullPathList = getFullPathList(commandLine); if (fullPathList == null) { return; } boolean createdAtLeastOnePath = false; IPathBiz pathBiz = SharedCache.getSharedCache().getPado().getCatalog().newInstance(IPathBiz.class); for (String fullPath : fullPathList) { String gridId = pathBiz.getBizContext().getGridService().getGridId(fullPath); if (gridId == null) { PadoShell.printlnError(this, fullPath + ": Unable to determine grid ID"); } else { String gridPath = GridUtil.getChildPath(fullPath); String colocatedWithFullPath = padoShell.getFullPath(colocatedWith); String colocatedWithGridPath = GridUtil.getChildPath(colocatedWithFullPath); boolean created = pathBiz.createPath(gridId, gridPath, pathType, diskStoreName, gatewaySenderIds, colocatedWithGridPath, redundantCopies, numBuckets, recursive); if (created == false) { PadoShell.printlnError(this, fullPath + ": Path creation failed"); } else { createdAtLeastOnePath = true; if (verbose) { PadoShell.println(this, "Created path '" + fullPath + "'"); } } } } if (createdAtLeastOnePath) { SharedCache.getSharedCache().refresh(); } }
From source file:de.mat.utils.pdftools.PdfMerge.java
@Override protected boolean validateCmdLine(CommandLine cmdLine) throws Throwable { if (cmdLine.getArgList().size() < 1) { return false; }/* w w w. j a v a2 s . c o m*/ return true; }
From source file:com.globalsight.ling.tm3.integration.TokenizeCommand.java
@Override protected void handle(CommandLine command) throws Exception { GlobalSightLocale locale = (GlobalSightLocale) getDataFactory().getLocaleById(32); if (locale == null) { System.out.println("No such locale"); System.exit(1);/*from w w w.j a v a 2s .com*/ } List<String> args = command.getArgList(); if (args.size() == 0) { System.out.println("no filename"); System.exit(1); } File f = new File(args.get(0)); if (!f.exists()) { System.out.println("File '" + f + "' does not exist"); System.exit(1); } BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8")); for (String line = r.readLine(); line != null; line = r.readLine()) { System.out.println("Args: " + line); GSTuvData data = new GSTuvData(line, locale); for (String s : data.getTokens()) { System.out.print("[" + s + "]"); if (s.length() == 1) { System.out.print(" (" + (int) s.charAt(0) + ")"); } System.out.println(""); } } }
From source file:com.netcrest.pado.tools.pado.command.mkpath.java
/** * Converts the path arguments to a list of full paths. * @param commandLine Command line/*from ww w .j a v a 2 s. c om*/ * @return null if error. */ @SuppressWarnings("unchecked") private List<String> getFullPathList(CommandLine commandLine) { // Check the specified paths and build the full paths List<String> argList = commandLine.getArgList(); String currentPath = padoShell.getCurrentPath(); List<String> fullPathList = new ArrayList<String>(argList.size() - 1); for (int i = 1; i < argList.size(); i++) { String path = (String) commandLine.getArgList().get(i); String fullPath = padoShell.getFullPath(path, currentPath); String gridPath = GridUtil.getChildPath(fullPath); if (gridPath.length() == 0) { PadoShell.printlnError(this, path + ": Invalid path. Top-level paths not allowed."); return null; } fullPathList.add(fullPath); } return fullPathList; }
From source file:com.yahoo.storm.yarn.StormMasterCommand.java
@Override public void process(CommandLine cl) throws Exception { String config_file = null;//from w ww . j a v a 2s . com List remaining_args = cl.getArgList(); if (remaining_args != null && !remaining_args.isEmpty()) { config_file = (String) remaining_args.get(0); } Map stormConf = Config.readStormConfig(null); String appId = cl.getOptionValue("appId"); if (appId == null) { throw new IllegalArgumentException("-appId is required"); } StormOnYarn storm = null; try { storm = StormOnYarn.attachToApp(appId, stormConf); StormMaster.Client client = storm.getClient(); switch (cmd) { case GET_STORM_CONFIG: downloadStormYaml(client, cl.getOptionValue("output")); break; case SET_STORM_CONFIG: String storm_conf_str = JSONValue.toJSONString(stormConf); try { client.setStormConf(storm_conf_str); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case ADD_SUPERVISORS: String supversiors = cl.getOptionValue("supervisors", "1"); try { client.addSupervisors(new Integer(supversiors).intValue()); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case START_NIMBUS: try { client.startNimbus(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case STOP_NIMBUS: try { client.stopNimbus(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case START_UI: try { client.startUI(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case STOP_UI: try { client.stopUI(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case START_SUPERVISORS: try { client.startSupervisors(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case STOP_SUPERVISORS: try { client.stopSupervisors(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; case SHUTDOWN: try { client.shutdown(); } catch (TTransportException ex) { LOG.info(ex.toString()); } break; } } finally { if (storm != null) { storm.stop(); } } }
From source file:com.netcrest.pado.tools.pado.command.rm.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) 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;// ww w . ja v a 2 s. co m } if (path == null && bufferName == null) { path = padoShell.getCurrentPath(); } if (path != null) { if (commandLine.getArgList().size() < 2) { PadoShell.printlnError(this, "Invalid command. Key or key fields must be specified."); return; } String input = (String) commandLine.getArgList().get(1); Object key = null; if (input.startsWith("'")) { int lastIndex = -1; if (input.endsWith("'") == false) { lastIndex = input.length(); } else { lastIndex = input.lastIndexOf("'"); } if (lastIndex <= 1) { PadoShell.printlnError(this, "Invalid key. Empty string not allowed."); return; } key = input.subSequence(1, lastIndex); // lastIndex exclusive } else { key = ObjectUtil.getPrimitive(padoShell, input, false); if (key == null) { key = padoShell.getQueryKey(argList, 1); } } if (key == null) { return; } String fullPath = padoShell.getFullPath(path); String gridPath = GridUtil.getChildPath(fullPath); String gridId = SharedCache.getSharedCache().getGridId(fullPath); IGridMapBiz gridMapBiz = SharedCache.getSharedCache().getPado().getCatalog() .newInstance(IGridMapBiz.class, gridPath); gridMapBiz.getBizContext().getGridContextClient().setGridIds(gridId); gridMapBiz.remove(key); } else { // Get key from the buffer BufferInfo bufferInfo = SharedCache.getSharedCache().getBufferInfo(bufferName); if (bufferInfo == null) { PadoShell.printlnError(this, bufferName + ": Buffer undefined."); return; } String gridId = bufferInfo.getGridId(); String gridPath = bufferInfo.getGridPath(); if (gridId == null || gridPath == null) { PadoShell.printlnError(this, bufferName + ": Invalid buffer. This buffer does not contain keys."); return; } if (argList.size() == 1) { PadoShell.printlnError(this, bufferName + ": Buffer number(s) not specified."); return; } Map<Integer, Object> keyMap = bufferInfo.getKeyMap(argList, 1); if (keyMap.size() > 0) { IGridMapBiz gridMapBiz = SharedCache.getSharedCache().getPado().getCatalog() .newInstance(IGridMapBiz.class, gridPath); gridMapBiz.getBizContext().getGridContextClient().setGridIds(gridId); gridMapBiz.removeAll(keyMap.values()); bufferInfo.getRemovedRowNumberSet().addAll(keyMap.keySet()); } } }
From source file:com.netcrest.pado.tools.pado.command.less.java
@Override @SuppressWarnings({ "rawtypes" }) public void run(CommandLine commandLine, String command) throws Exception { boolean isRefresh = commandLine.hasOption("refresh"); String bufferName = commandLine.getOptionValue("buffer"); String path = null;/*w ww . ja va 2 s.co m*/ if (commandLine.getArgList().size() == 1) { if (bufferName == null) { PadoShell.printlnError(this, "Path not specified."); return; } } else { path = (String) commandLine.getArgList().get(1); } IScrollableResultSet rs = null; if (path == null) { BufferInfo bufferInfo = SharedCache.getSharedCache().getBufferInfo(bufferName); if (bufferInfo == null) { PadoShell.printlnError(this, bufferName + ": Buffer undefined."); return; } rs = bufferInfo.getScrollableResultSet(); rs.setFetchSize(padoShell.getFetchSize()); } else { boolean showKeys = PadoShellUtil.hasSingleLetterOption(commandLine, 'k', "refresh"); boolean showValues = PadoShellUtil.hasSingleLetterOption(commandLine, 'v', "refresh"); rs = queryPath(path, isRefresh, showKeys, showValues); if (rs == null) { return; } if (bufferName != null) { String fullPath = padoShell.getFullPath(path); String gridPath = GridUtil.getChildPath(fullPath); String gridId = SharedCache.getSharedCache().getPado().getCatalog().getGridService() .getGridId(fullPath); SharedCache.getSharedCache().putBufferInfo(bufferName, new BufferInfo(bufferName, command, this, rs, gridId, gridPath)); } } if (padoShell.isInteractiveMode()) { ResultSetDisplay.display(rs); } else { // Show header only for the first set. int startRowNum = 1; int rowsPrinted = PrintUtil.printScrollableResultSet(rs, startRowNum, true); startRowNum += rowsPrinted; if (rs.nextSet()) { do { rowsPrinted = PrintUtil.printScrollableResultSet(rs, startRowNum, false); startRowNum += rowsPrinted; } while (rs.nextSet()); } } }