List of usage examples for org.apache.commons.cli CommandLine getArgs
public String[] getArgs()
From source file:com.knewton.mapreduce.cassandra.WriteSampleSSTable.java
/** * Called to validate the parameters.//ww w. j ava 2 s. com * * @param args * @throws ParseException */ private static void buildParametersFromArgs(String[] args) throws ParseException { CommandLineParser cliParser = new BasicParser(); Options options = buildOptions(); CommandLine cli = cliParser.parse(options, args); if (cli.getArgs().length < 1 || cli.hasOption('h')) { printUsage(options); } tableDirectory = new File(cli.getArgs()[0] + String.format("/%s/%s/", KEYSPACE_NAME, COLUMN_FAMILY_NAME)); tableDirectory.mkdirs(); numberOfStudents = Integer.parseInt(cli.getOptionValue('s', String.valueOf(DEFAULT_NUM_STUDENTS))); eventsPerStudent = Integer .parseInt(cli.getOptionValue('e', String.valueOf(DEFAULT_NUM_EVENTS_PER_STUDENT))); }
From source file:com.cloudera.flume.handlers.debug.TextToCollector.java
static void core(CommandLine cmd) throws IOException { String[] argv = cmd.getArgs(); Benchmark b = new Benchmark(); b.mark("init"); FlumeConfiguration conf = FlumeConfiguration.get(); ThriftEventSink tes = new ThriftEventSink(conf.getCollectorHost(), conf.getCollectorPort(), false); tes.open();/*from ww w. ja va2 s . co m*/ MemorySinkSource mem = cmd.hasOption("m") ? new MemorySinkSource() : null; for (String f : argv) { EventSource src = null; if (cmd.hasOption("l")) { b.mark("log4jtext"); src = new Log4jTextFileSource(f); } else if (cmd.hasOption("t")) { b.mark("random access text"); src = new TextFileSource(f); } else { b.mark("buffered reader text"); src = new TextReaderSource(f); } src.open(); b.mark("fileread"); if (mem != null) { EventUtil.dumpAll(src, mem); } else { EventUtil.dumpAll(src, tes); } src.close(); } b.mark("memdump"); if (mem != null) { EventUtil.dumpAll(mem, tes); } b.mark("done"); b.done(); tes.close(); }
From source file:alluxio.cli.CommandUtils.java
/** * Checks the number of non-option arguments equals n for command. * * @param cmd command instance/*w w w . ja v a 2 s. c om*/ * @param cl parsed commandline arguments * @param n an integer * @throws InvalidArgumentException if the number does not equal n */ public static void checkNumOfArgsEquals(Command cmd, CommandLine cl, int n) throws InvalidArgumentException { if (cl.getArgs().length != n) { throw new InvalidArgumentException( ExceptionMessage.INVALID_ARGS_NUM.getMessage(cmd.getCommandName(), n, cl.getArgs().length)); } }
From source file:alluxio.cli.CommandUtils.java
/** * Checks the number of non-option arguments is no less than n for command. * * @param cmd command instance//from w w w. ja va 2 s . com * @param cl parsed commandline arguments * @param n an integer * @throws InvalidArgumentException if the number is smaller than n */ public static void checkNumOfArgsNoLessThan(Command cmd, CommandLine cl, int n) throws InvalidArgumentException { if (cl.getArgs().length < n) { throw new InvalidArgumentException(ExceptionMessage.INVALID_ARGS_NUM_INSUFFICIENT .getMessage(cmd.getCommandName(), n, cl.getArgs().length)); } }
From source file:alluxio.cli.CommandUtils.java
/** * Checks the number of non-option arguments is no more than n for command. * * @param cmd command instance/*w w w.j a va 2 s . c om*/ * @param cl parsed commandline arguments * @param n an integer * @throws InvalidArgumentException if the number is greater than n */ public static void checkNumOfArgsNoMoreThan(Command cmd, CommandLine cl, int n) throws InvalidArgumentException { if (cl.getArgs().length > n) { throw new InvalidArgumentException(ExceptionMessage.INVALID_ARGS_NUM_TOO_MANY .getMessage(cmd.getCommandName(), n, cl.getArgs().length)); } }
From source file:com.aliyun.openservices.odps.console.resource.DropFunctionCommand.java
public static DropFunctionCommand parse(String commandString, ExecutionContext sessionContext) throws ODPSConsoleException { String[] args = CommandParserUtils.getCommandTokens(commandString); if (args.length < 2) { return null; }//from w ww . j a v a 2 s. com // ??DROPFUNCTION FUNCTION_NAME if (args[0].equalsIgnoreCase("DROP") && args[1].equalsIgnoreCase("FUNCTION")) { if (args.length == 3) { return new DropFunctionCommand(null, args[2], commandString, sessionContext); } else { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND); } } else if (args[0].equalsIgnoreCase("DELETE") && args[1].equalsIgnoreCase("FUNCTION")) { Options opts = initOptions(); CommandLine cl = CommandParserUtils.getCommandLine(args, opts); if (3 != cl.getArgs().length) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND); } String project = cl.getOptionValue("p"); return new DropFunctionCommand(project, cl.getArgs()[2], commandString, sessionContext); } return null; }
From source file:com.aliyun.openservices.odps.console.resource.DropResourceCommand.java
public static DropResourceCommand parse(String commandString, ExecutionContext sessionContext) throws ODPSConsoleException { String[] args = CommandParserUtils.getCommandTokens(commandString); if (args.length < 2) { return null; }//from w ww.j ava2 s .c o m // ??DROPRESOURCE RESOURCE_NAME if (args[0].equalsIgnoreCase("DROP") && args[1].equalsIgnoreCase("RESOURCE")) { if (args.length == 3) { return new DropResourceCommand(null, args[2], commandString, sessionContext); } else { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND); } } else if (args[0].equalsIgnoreCase("DELETE") && args[1].equalsIgnoreCase("RESOURCE")) { Options opts = initOptions(); CommandLine cl = CommandParserUtils.getCommandLine(args, opts); if (3 != cl.getArgs().length) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND); } String project = cl.getOptionValue("p"); return new DropResourceCommand(project, cl.getArgs()[2], commandString, sessionContext); } return null; }
From source file:com.aliyun.openservices.odps.console.pub.StopInstanceCommand.java
public static StopInstanceCommand parse(String commandString, ExecutionContext sessionContext) throws ODPSConsoleException { if (commandString.toUpperCase().startsWith("KILL")) { String temp[] = commandString.trim().replaceAll("\\s+", " ").split(" "); CommandLine cl = getCommandLine(temp); if (2 == cl.getArgs().length) { return new StopInstanceCommand(commandString, sessionContext, temp[1], false); }//from ww w.j ava 2 s . c o m if (1 != cl.getArgs().length) { throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "[invalid parameters]"); } if (cl.hasOption("sync")) { return new StopInstanceCommand(commandString, sessionContext, cl.getOptionValue("sync"), true); } } return null; }
From source file:net.mindengine.galen.parser.GalenPageActionReader.java
private static GalenPageAction checkActionFrom(String[] args, String originalText) { Options options = new Options(); options.addOption("i", "include", true, "include tags"); options.addOption("e", "exclude", true, "exclude tags"); org.apache.commons.cli.CommandLineParser parser = new PosixParser(); try {/* w w w. jav a2 s. c o m*/ CommandLine cmd = parser.parse(options, args); String[] leftoverArgs = cmd.getArgs(); if (leftoverArgs == null || leftoverArgs.length < 2) { throw new SyntaxException(UNKNOWN_LINE, "There are no page specs: " + originalText); } List<String> specs = new LinkedList<String>(); for (int i = 1; i < leftoverArgs.length; i++) { specs.add(leftoverArgs[i]); } return new GalenPageActionCheck().withSpecs(specs).withIncludedTags(readTags(cmd.getOptionValue("i"))) .withExcludedTags(readTags(cmd.getOptionValue("e"))); } catch (Exception e) { throw new SyntaxException(UNKNOWN_LINE, "Couldn't parse: " + originalText, e); } }
From source file:com.aliyun.openservices.odps.console.commands.ShowTablesCommand.java
static String getProjectNameFromPublicCmd(String cmd) throws ODPSConsoleException { String projectName = null;/*from w ww . j a v a2 s. com*/ CommandLine cl = getCommandLine(cmd); if (cl.getArgs().length > 2) { // Any args except 'ls' and 'tables' should be errors throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND); } if (!cl.hasOption("project")) { return null; } projectName = cl.getOptionValue("project"); return projectName; }