List of usage examples for org.apache.commons.cli Option getOpt
public String getOpt()
From source file:org.apache.hadoop.hbase.regionserver.DataBlockEncodingTool.java
private static void printUsage(Options options) { System.err.println("Usage:"); System.err.println(String.format("./hbase %s <options>", DataBlockEncodingTool.class.getName())); System.err.println("Options:"); for (Object it : options.getOptions()) { Option opt = (Option) it; if (opt.hasArg()) { System.err//from ww w .j a v a 2 s. c o m .println(String.format("-%s %s: %s", opt.getOpt(), opt.getArgName(), opt.getDescription())); } else { System.err.println(String.format("-%s: %s", opt.getOpt(), opt.getDescription())); } } }
From source file:org.apache.hadoop.net.PodCIDRToNodeMapping.java
public static void main(String[] args) throws ParseException { Options options = new Options(); Option nameOption = new Option("n", true, "Name to resolve"); nameOption.setRequired(true);//from w ww . j a v a 2 s . co m options.addOption(nameOption); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); BasicConfigurator.configure(); Logger.getRootLogger().setLevel(Level.DEBUG); PodCIDRToNodeMapping plugin = new PodCIDRToNodeMapping(); Configuration conf = new Configuration(); plugin.setConf(conf); String nameToResolve = cmd.getOptionValue(nameOption.getOpt()); List<String> networkPathDirs = plugin.resolve(Lists.newArrayList(nameToResolve)); log.info("Resolved " + nameToResolve + " to " + networkPathDirs); }
From source file:org.apache.hadoop.yarn.client.cli.ApplicationCLI.java
@SuppressWarnings("unchecked") private boolean hasAnyOtherCLIOptions(CommandLine cliParser, Options opts, String excludeOption) { Collection<Option> ops = opts.getOptions(); for (Option op : ops) { // Skip exclude option from the option list if (op.getOpt().equals(excludeOption)) { continue; }/*from ww w. j av a 2 s . c o m*/ if (cliParser.hasOption(op.getOpt())) { return true; } } return false; }
From source file:org.apache.ivory.cli.IvoryCLI.java
private void instanceCommand(CommandLine commandLine) throws IvoryCLIException, IOException { String ivoryUrl = validateIvoryUrl(commandLine); IvoryClient client = new IvoryClient(ivoryUrl); Set<String> optionsList = new HashSet<String>(); for (Option option : commandLine.getOptions()) { optionsList.add(option.getOpt()); }// www . ja va2 s . c o m String result = null; String type = commandLine.getOptionValue(ENTITY_TYPE_OPT); String entity = commandLine.getOptionValue(ENTITY_NAME_OPT); String start = commandLine.getOptionValue(START_OPT); String end = commandLine.getOptionValue(END_OPT); String filePath = commandLine.getOptionValue(FILE_PATH_OPT); String runid = commandLine.getOptionValue(RUNID_OPT); validateInstanceCommands(optionsList, entity, type, start, end, filePath); if (optionsList.contains(RUNNING_OPT)) { result = client.getRunningInstances(type, entity); } else if (optionsList.contains(STATUS_OPT)) { result = client.getStatusOfInstances(type, entity, start, end, runid); } else if (optionsList.contains(KILL_OPT)) { result = client.killInstances(type, entity, start, end); } else if (optionsList.contains(SUSPEND_OPT)) { result = client.suspendInstances(type, entity, start, end); } else if (optionsList.contains(RESUME_OPT)) { result = client.resumeInstances(type, entity, start, end); } else if (optionsList.contains(RERUN_OPT)) { result = client.rerunInstances(type, entity, start, end, filePath); } else { throw new IvoryCLIException("Invalid command"); } OUT_STREAM.println(result); }
From source file:org.apache.ivory.cli.IvoryCLI.java
private void entityCommand(CommandLine commandLine) throws IvoryCLIException, IOException { String ivoryUrl = validateIvoryUrl(commandLine); IvoryClient client = new IvoryClient(ivoryUrl); Set<String> optionsList = new HashSet<String>(); for (Option option : commandLine.getOptions()) { optionsList.add(option.getOpt()); }// w w w . ja v a 2 s . c o m String result = null; String entityType = commandLine.getOptionValue(ENTITY_TYPE_OPT); String entityName = commandLine.getOptionValue(ENTITY_NAME_OPT); String filePath = commandLine.getOptionValue(FILE_PATH_OPT); validateEntityType(optionsList, entityType); if (optionsList.contains(SUBMIT_OPT)) { validateFilePath(optionsList, filePath); result = client.submit(entityType, filePath); } else if (optionsList.contains(UPDATE_OPT)) { validateFilePath(optionsList, filePath); validateEntityName(optionsList, entityName); result = client.update(entityType, entityName, filePath); } else if (optionsList.contains(SUBMIT_AND_SCHEDULE_OPT)) { validateFilePath(optionsList, filePath); result = client.submitAndSchedule(entityType, filePath); } else if (optionsList.contains(VALIDATE_OPT)) { validateFilePath(optionsList, filePath); result = client.validate(entityType, filePath); } else if (optionsList.contains(SCHEDULE_OPT)) { validateEntityName(optionsList, entityName); result = client.schedule(entityType, entityName); } else if (optionsList.contains(SUSPEND_OPT)) { validateEntityName(optionsList, entityName); result = client.suspend(entityType, entityName); } else if (optionsList.contains(RESUME_OPT)) { validateEntityName(optionsList, entityName); result = client.resume(entityType, entityName); } else if (optionsList.contains(DELETE_OPT)) { validateEntityName(optionsList, entityName); result = client.delete(entityType, entityName); } else if (optionsList.contains(STATUS_OPT)) { validateEntityName(optionsList, entityName); result = client.getStatus(entityType, entityName); } else if (optionsList.contains(DEFINITION_OPT)) { validateEntityName(optionsList, entityName); result = client.getDefinition(entityType, entityName); } else if (optionsList.contains(DEPENDENCY_OPT)) { validateEntityName(optionsList, entityName); result = client.getDependency(entityType, entityName); } else if (optionsList.contains(LIST_OPT)) { result = client.getEntityList(entityType); } else if (optionsList.contains(HELP_CMD)) { OUT_STREAM.println("Ivory Help"); } else { throw new IvoryCLIException("Invalid command"); } OUT_STREAM.println(result); }
From source file:org.apache.ivory.cli.IvoryCLI.java
private void adminCommand(CommandLine commandLine) throws IvoryCLIException { validateIvoryUrl(commandLine);//from www. java 2 s . c o m Set<String> optionsList = new HashSet<String>(); for (Option option : commandLine.getOptions()) { optionsList.add(option.getOpt()); } if (optionsList.contains(VERSION_OPTION)) { OUT_STREAM.println("Ivory server build version: 1.0"); } else if (optionsList.contains(HELP_CMD)) { OUT_STREAM.println("Ivory Help"); } }
From source file:org.apache.marmotta.loader.core.MarmottaLoader.java
public static Configuration parseOptions(String[] args) throws ParseException { Options options = buildOptions();/* ww w .j a va2 s . co m*/ CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); Configuration result = new MapConfiguration(new HashMap<String, Object>()); if (cmd.hasOption('B')) { // check backends Set<String> existing = Sets .newHashSet(Iterators.transform(backends.iterator(), new BackendIdentifierFunction())); if (!existing.contains(cmd.getOptionValue('B'))) { throw new ParseException("the backend " + cmd.getOptionValue('B') + " does not exist"); } result.setProperty(LoaderOptions.BACKEND, cmd.getOptionValue('B')); } if (cmd.hasOption('b')) { result.setProperty(LoaderOptions.BASE_URI, cmd.getOptionValue('b')); } if (cmd.hasOption('z')) { result.setProperty(LoaderOptions.COMPRESSION, CompressorStreamFactory.GZIP); } if (cmd.hasOption('j')) { result.setProperty(LoaderOptions.COMPRESSION, CompressorStreamFactory.BZIP2); } if (cmd.hasOption('c')) { result.setProperty(LoaderOptions.CONTEXT, cmd.getOptionValue('c')); } if (cmd.hasOption('t')) { RDFFormat fmt = getRDFFormat(cmd.getOptionValue('t')); if (fmt == null) { throw new ParseException("unrecognized MIME type: " + cmd.getOptionValue('t')); } result.setProperty(LoaderOptions.FORMAT, fmt.getDefaultMIMEType()); } if (cmd.hasOption('f')) { result.setProperty(LoaderOptions.FILES, Arrays.asList(cmd.getOptionValues('f'))); } if (cmd.hasOption('d')) { result.setProperty(LoaderOptions.DIRS, Arrays.asList(cmd.getOptionValues('d'))); } if (cmd.hasOption('a')) { result.setProperty(LoaderOptions.ARCHIVES, Arrays.asList(cmd.getOptionValues('a'))); } if (cmd.hasOption('s')) { result.setProperty(LoaderOptions.STATISTICS_ENABLED, true); result.setProperty(LoaderOptions.STATISTICS_GRAPH, cmd.getOptionValue('s')); } if (cmd.hasOption('D')) { for (Map.Entry e : cmd.getOptionProperties("D").entrySet()) { result.setProperty(e.getKey().toString(), e.getValue()); } } for (LoaderBackend b : backends) { for (Option option : b.getOptions()) { if (cmd.hasOption(option.getOpt())) { String key = String.format("backend.%s.%s", b.getIdentifier(), option.getLongOpt() != null ? option.getLongOpt() : option.getOpt()); if (option.hasArg()) { if (option.hasArgs()) { result.setProperty(key, Arrays.asList(cmd.getOptionValues(option.getOpt()))); } else { result.setProperty(key, cmd.getOptionValue(option.getOpt())); } } else { result.setProperty(key, true); } } } } return result; }
From source file:org.apache.maven.cli.CLIManagerDocumentationTest.java
public String getOptionsAsHtml() { StringBuilder sb = new StringBuilder(512); boolean a = true; sb.append(/* ww w . ja v a 2 s . c o m*/ "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>"); for (Option option : new CLIManagerExtension().getOptions()) { a = !a; sb.append("<tr class='").append(a ? 'a' : 'b').append("'><td><code>-<a name='"); sb.append(option.getOpt()); sb.append("'>"); sb.append(option.getOpt()); sb.append("</a>,--<a name='"); sb.append(option.getLongOpt()); sb.append("'>"); sb.append(option.getLongOpt()); sb.append("</a>"); if (option.hasArg()) { if (option.hasArgName()) { sb.append(" <").append(option.getArgName()).append(">"); } else { sb.append(' '); } } sb.append("</code></td><td>"); sb.append(option.getDescription()); sb.append("</td></tr>"); sb.append(LS); } sb.append("</table>"); return sb.toString(); }
From source file:org.apache.maven.cli.CLIManagerTest.java
public String getOptionsAsHtml() { StringBuilder sb = new StringBuilder(); boolean a = true; sb.append(/*from ww w. j a v a 2 s .c o m*/ "<table border='1' class='zebra-striped'><tr class='a'><th><b>Options</b></th><th><b>Description</b></th></tr>"); for (Option option : new CLIManagerExtension().getOptions()) { a = !a; sb.append("<tr class='").append(a ? 'a' : 'b').append("'><td><code>-<a name='"); sb.append(option.getOpt()); sb.append("'>"); sb.append(option.getOpt()); sb.append("</a>,--<a name='"); sb.append(option.getLongOpt()); sb.append("'>"); sb.append(option.getLongOpt()); sb.append("</a>"); if (option.hasArg()) { if (option.hasArgName()) { sb.append(" <").append(option.getArgName()).append(">"); } else { sb.append(' '); } } sb.append("</code></td><td>"); sb.append(option.getDescription()); sb.append("</td></tr>"); sb.append(LS); } sb.append("</table>"); return sb.toString(); }
From source file:org.apache.maven.cli.MergedCommandLine.java
MergedCommandLine(CommandLine commandLine, CommandLine configFile) { // such a pity that Commons CLI does not offer either a builder or a formatter and we need to extend // to perform the merge. A formatter would mean we could unparse and reparse (not ideal but would work). // A builder would be ideal for this kind of merge like processing. super();//from w w w .j av a2s . c o m // the args are easy, cli first then config file for (String arg : commandLine.getArgs()) { addArg(arg); } for (String arg : configFile.getArgs()) { addArg(arg); } // now add all options, except for -D with cli first then config file List<Option> setPropertyOptions = new ArrayList<>(); for (Option opt : commandLine.getOptions()) { if (String.valueOf(CLIManager.SET_SYSTEM_PROPERTY).equals(opt.getOpt())) { setPropertyOptions.add(opt); } else { addOption(opt); } } for (Option opt : configFile.getOptions()) { addOption(opt); } // finally add the CLI system properties for (Option opt : setPropertyOptions) { addOption(opt); } }