List of usage examples for org.apache.commons.cli CommandLine getArgList
public List getArgList()
From source file:com.netcrest.pado.tools.pado.util.PadoShellUtil.java
/** * Returns an array of full paths determined by parsing all paths arguments * found in the specified commandLine. Duplicates are ignored. * //w w w . ja v a 2 s.co m * @param padoShell * PadoShell instance * @param commandLine * Command line with path arguments. * @return null if paths are not found in the specified commandLine. */ @SuppressWarnings("unchecked") public final static String[] getFullPaths(PadoShell padoShell, CommandLine commandLine) { List<String> argList = (List<String>) commandLine.getArgList(); if (argList.size() <= 1) { return null; } HashSet<String> set = new HashSet<String>(argList.size()); for (int i = 1; i < argList.size(); i++) { String path = argList.get(i); set.add(padoShell.getFullPath(path)); } String fullPaths[] = set.toArray(new String[set.size()]); return fullPaths; }
From source file:com.tractionsoftware.reshoot.Reshoot.java
private static CommandLine parseCommandLine(String[] args) { CommandLineParser parser = new GnuParser(); org.apache.commons.cli.Options options = new org.apache.commons.cli.Options(); // create the command-line options Option chrome = OptionBuilder.withDescription("use Chrome (for retina screenshots on retina displays)") .withLongOpt("chrome").create(); Option firefox = OptionBuilder.withDescription("use Firefox (for full scrollheight screenshots)") .withLongOpt("firefox").create(); options.addOption(chrome);/*from w w w . j a va 2 s . c om*/ options.addOption(firefox); // attempt to parse them, printing help if it fails try { CommandLine cmd = parser.parse(options, args); // make sure we have some files to process if (cmd.getArgList().isEmpty()) { showUsageAndExit(options); } return cmd; } catch (ParseException e) { showUsageAndExit(options); } return null; }
From source file:com.aliyun.openservices.odps.console.commands.DescribeInstanceCommand.java
public static DescribeInstanceCommand parse(String cmd, ExecutionContext ctx) throws ODPSConsoleException { if (cmd == null || ctx == null) { return null; }//from ww w . ja v a 2 s. co m Matcher m = PATTERN.matcher(cmd); boolean match = m.matches(); if (!match) { return null; } String input = m.group(3); if (input == null) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + " need specify one Instance Id."); } String[] inputs = new AntlrObject(input).getTokenStringArray(); CommandLine commandLine = getCommandLine(inputs); String projectName = null; if (commandLine.hasOption("p")) { projectName = commandLine.getOptionValue("p"); } if (commandLine.getArgList().size() != 1) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + " Invalid Instance Id."); } String resourceName = commandLine.getArgs()[0]; if (projectName == null) { projectName = ctx.getProjectName(); } return new DescribeInstanceCommand(resourceName, projectName, cmd, ctx); }
From source file:com.aliyun.openservices.odps.console.commands.DescribeResourceCommand.java
public static DescribeResourceCommand parse(String cmd, ExecutionContext ctx) throws ODPSConsoleException { if (cmd == null || ctx == null) { return null; }//from w w w . j a v a2 s . c om Matcher m = PATTERN.matcher(cmd); boolean match = m.matches(); if (!match) { return null; } String input = m.group(2); String[] inputs = new AntlrObject(input).getTokenStringArray(); CommandLine commandLine = getCommandLine(inputs); String projectName = null; if (commandLine.hasOption("p")) { projectName = commandLine.getOptionValue("p"); } if (commandLine.getArgList().size() != 1) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + " Invalid resource name."); } String resourceName = commandLine.getArgs()[0]; if (resourceName.contains(":")) { String[] result = resourceName.split(":", 2); if (projectName != null && (!result[0].equals(projectName))) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + " project name conflict."); } projectName = result[0]; resourceName = result[1]; } if (projectName == null) { projectName = ctx.getProjectName(); } return new DescribeResourceCommand(resourceName, projectName, cmd, ctx); }
From source file:com.aliyun.openservices.odps.console.commands.DescribeProjectCommand.java
public static AbstractCommand parse(String cmd, ExecutionContext ctx) throws ODPSConsoleException { if (cmd == null || ctx == null) { return null; }/*w w w .j av a 2 s .co m*/ String[] tokens = new AntlrObject(cmd).getTokenStringArray(); if (tokens.length < 2) { return null; } if (!("DESC".equalsIgnoreCase(tokens[0]) || "DESCRIBE".equalsIgnoreCase(tokens[0]))) { return null; } if (!("PROJECT".equalsIgnoreCase(tokens[1]))) { return null; } CommandLine parser = null; try { parser = new GnuParser().parse(getOptions(), tokens); } catch (ParseException e) { throw new ODPSConsoleException(e.getMessage(), e); } boolean extended = parser.hasOption("extended"); if (parser.getArgList().size() != 3) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND); } String projectName = parser.getArgs()[2]; return new DescribeProjectCommand(projectName, extended, cmd, ctx); }
From source file:com.netcrest.pado.tools.pado.util.PadoShellUtil.java
/** * Returns an array of grid IDs found in the specified commandLine with the * -grid option./*from www . j a v a 2 s. com*/ * * @param command * Commnand * @param commandLine * Command line with the -grid option. Grid IDs must be comma * separated with no spaces. * @param isGridAllBothRequired * true if both -grid and -all must present in the specified * commandLine. * @return */ @SuppressWarnings("unchecked") public final static String[] getGridIds(ICommand command, CommandLine commandLine, boolean isGridAllBothRequired) { boolean isAllPaths = commandLine.hasOption("all"); List<String> argList = (List<String>) commandLine.getArgList(); if (isAllPaths && argList.size() > 1) { PadoShell.printlnError(command, "Both '-all' and path not allowed."); return null; } String gridValue = commandLine.getOptionValue("grid"); if (isGridAllBothRequired) { if (gridValue != null && isAllPaths == false) { PadoShell.printlnError(command, "'-grid' requires '-all'"); return null; } } String gridIds[] = null; if (gridValue == null) { String gridId = SharedCache.getSharedCache().getPado().getGridId(); gridIds = new String[] { gridId }; } else { gridIds = gridValue.split(","); List<String> gridIdList = new ArrayList<String>(gridIds.length); for (String gridId : gridIds) { if (gridId.length() == 0) { continue; } if (SharedCache.getSharedCache().getGridInfo(gridId) == null) { PadoShell.printlnError(command, gridId + ": Undefined grid ID."); return null; } if (gridIdList.contains(gridId) == false) { gridIdList.add(gridId); } } gridIds = gridIdList.toArray(new String[gridIdList.size()]); } return gridIds; }
From source file:com.teradata.benchto.driver.DriverApp.java
private static CommandLine processArguments(String[] args) throws ParseException { DefaultParser defaultParser = new DefaultParser(); Options options = createOptions();//from ww w . j a v a 2 s .c o m CommandLine commandLine = defaultParser.parse(options, args); if (commandLine.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Benchto driver", options); System.exit(0); } exposeArgumentsAsPropertiesForSpring(commandLine); checkState(commandLine.getArgList().isEmpty(), "Added extra non used arguments: %s", commandLine.getArgList()); return commandLine; }
From source file:brut.apktool.Main.java
private static void cmdPublicizeResources(CommandLine cli) throws AndrolibException { int paraCount = cli.getArgList().size(); String apkName = (String) cli.getArgList().get(paraCount - 1); new Androlib().publicizeResources(new File(apkName)); }
From source file:brut.apktool.Main.java
private static void cmdInstallFramework(CommandLine cli) throws AndrolibException { int paraCount = cli.getArgList().size(); String apkName = (String) cli.getArgList().get(paraCount - 1); ApkOptions apkOptions = new ApkOptions(); if (cli.hasOption("p") || cli.hasOption("frame-path")) { apkOptions.frameworkFolderLocation = cli.getOptionValue("p"); }/*ww w . ja v a 2s . c o m*/ if (cli.hasOption("t") || cli.hasOption("tag")) { apkOptions.frameworkTag = cli.getOptionValue("t"); } new Androlib(apkOptions).installFramework(new File(apkName)); }
From source file:com.alibaba.jstorm.flux.Flux.java
private static void runCli(CommandLine cmd) throws Exception { if (!cmd.hasOption(OPTION_NO_SPLASH)) { printSplash();/*from w w w .j a va 2 s .c o m*/ } boolean dumpYaml = cmd.hasOption("dump-yaml"); TopologyDef topologyDef = null; String filePath = (String) cmd.getArgList().get(0); // TODO conditionally load properties from a file our resource String filterProps = null; if (cmd.hasOption(OPTION_FILTER)) { filterProps = cmd.getOptionValue(OPTION_FILTER); } boolean envFilter = cmd.hasOption(OPTION_ENV_FILTER); if (cmd.hasOption(OPTION_RESOURCE)) { printf("Parsing classpath resource: %s", filePath); topologyDef = FluxParser.parseResource(filePath, dumpYaml, true, filterProps, envFilter); } else { printf("Parsing file: %s", new File(filePath).getAbsolutePath()); topologyDef = FluxParser.parseFile(filePath, dumpYaml, true, filterProps, envFilter); } String topologyName = topologyDef.getName(); // merge contents of `config` into topology config Config conf = FluxBuilder.buildConfig(topologyDef); ExecutionContext context = new ExecutionContext(topologyDef, conf); StormTopology topology = FluxBuilder.buildTopology(context); if (!cmd.hasOption(OPTION_NO_DETAIL)) { printTopologyInfo(context); } if (!cmd.hasOption(OPTION_DRY_RUN)) { if (cmd.hasOption(OPTION_REMOTE)) { LOG.info("Running remotely..."); try { // should the topology be active or inactive SubmitOptions submitOptions = null; if (cmd.hasOption(OPTION_INACTIVE)) { LOG.info("Deploying topology in an INACTIVE state..."); submitOptions = new SubmitOptions(TopologyInitialStatus.INACTIVE); } else { LOG.info("Deploying topology in an ACTIVE state..."); submitOptions = new SubmitOptions(TopologyInitialStatus.ACTIVE); } StormSubmitter.submitTopology(topologyName, conf, topology, submitOptions); } catch (Exception e) { LOG.warn("Unable to deploy topology to remote cluster.", e); } } else { LOG.info("Running in local mode..."); String sleepStr = cmd.getOptionValue(OPTION_SLEEP); Long sleepTime = DEFAULT_LOCAL_SLEEP_TIME; if (sleepStr != null) { sleepTime = Long.parseLong(sleepStr); } LOG.debug("Sleep time: {}", sleepTime); LocalCluster cluster = null; // in-process or external zookeeper if (cmd.hasOption(OPTION_ZOOKEEPER)) { String zkStr = cmd.getOptionValue(OPTION_ZOOKEEPER); LOG.info("Using ZooKeeper at '{}' instead of in-process one.", zkStr); long zkPort = DEFAULT_ZK_PORT; String zkHost = null; if (zkStr.contains(":")) { String[] hostPort = zkStr.split(":"); zkHost = hostPort[0]; zkPort = hostPort.length > 1 ? Long.parseLong(hostPort[1]) : DEFAULT_ZK_PORT; } else { zkHost = zkStr; } // the following constructor is only available in 0.9.3 and later /* try { cluster = new LocalCluster(zkHost, zkPort); } catch (NoSuchMethodError e){ LOG.error("The --zookeeper option can only be used with Apache Storm 0.9.3 and later."); System.exit(1); }*/ LOG.error("sorry, jstorm don't support this operation!!!"); System.exit(1); } else { cluster = new LocalCluster(); } cluster.submitTopology(topologyName, conf, topology); Utils.sleep(sleepTime); cluster.killTopology(topologyName); cluster.shutdown(); } } }