Java Code Examples for com.beust.jcommander.Parameters#hidden()
The following examples show how to use
com.beust.jcommander.Parameters#hidden() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomJCommander.java From terracotta-platform with Apache License 2.0 | 6 votes |
private void appendCommands(StringBuilder out, String indent, Map<String, JCommander> commands, boolean hasCommands) { if (hasCommands) { out.append(lineSeparator()).append("Commands:").append(lineSeparator()); for (Map.Entry<String, JCommander> command : commands.entrySet()) { Object arg = command.getValue().getObjects().get(0); Parameters p = arg.getClass().getAnnotation(Parameters.class); String name = command.getKey(); if (p == null || !p.hidden()) { String description = getCommandDescription(name); out.append(indent).append(" ").append(name).append(" ").append(description).append(lineSeparator()); appendUsage(commandRepository.getCommand(name), out, indent + " "); // Options for this command JCommander jc = command.getValue(); appendOptions(jc, out, " "); out.append(lineSeparator()); } } } }
Example 2
Source File: HelpCommand.java From geowave with Apache License 2.0 | 4 votes |
@Override public void execute(final OperationParams inputParams) { final CommandLineOperationParams params = (CommandLineOperationParams) inputParams; final List<String> nameArray = new ArrayList<>(); final OperationRegistry registry = OperationRegistry.getInstance(); StringBuilder builder = new StringBuilder(); Operation lastOperation = null; for (final Map.Entry<String, Operation> entry : params.getOperationMap().entrySet()) { if (entry.getValue() == this) { continue; } nameArray.add(entry.getKey()); lastOperation = entry.getValue(); } if (lastOperation == null) { lastOperation = registry.getOperation(GeoWaveTopLevelSection.class).createInstance(); } if (lastOperation != null) { final String usage = lastOperation.usage(); if (usage != null) { System.out.println(usage); } else { // This is done because if we don't, then JCommander will // consider the given parameters as the Default parameters. // It's also done so that we can parse prefix annotations // and special delegate processing. final JCommanderPrefixTranslator translator = new JCommanderPrefixTranslator(); translator.addObject(lastOperation); final JCommanderTranslationMap map = translator.translate(); map.createFacadeObjects(); // Copy default parameters over for help display. map.transformToFacade(); // Execute a prepare // Add processed objects final JCommander jc = new JCommander(); for (final Object obj : map.getObjects()) { jc.addObject(obj); } final String programName = StringUtils.join(nameArray, " "); jc.setProgramName(programName); jc.getUsageFormatter().usage(builder); // Trim excess newlines. final String operations = builder.toString().trim(); builder = new StringBuilder(); builder.append(operations); builder.append("\n\n"); // Add sub-commands final OperationEntry lastEntry = registry.getOperation(lastOperation.getClass()); // Cast to list so we can sort it based on operation name. final List<OperationEntry> children = new ArrayList<>(lastEntry.getChildren()); Collections.sort(children, getOperationComparator()); if (children.size() > 0) { builder.append(" Commands:\n"); for (final OperationEntry childEntry : children) { // Get description annotation final Parameters p = childEntry.getOperationClass().getAnnotation(Parameters.class); // If not hidden, then output it. if ((p == null) || !p.hidden()) { builder.append( String.format( " %s%n", StringUtils.join(childEntry.getOperationNames(), ", "))); if (p != null) { final String description = p.commandDescription(); builder.append(String.format(" %s%n", description)); } else { builder.append(" <no description>\n"); } builder.append("\n"); } } } // Trim excess newlines. final String output = builder.toString().trim(); System.out.println(output); } } }