@Override protected void printHelp(CommandContext ctx) { ParsedCommandLine args = ctx.getParsedCommandLine(); try { if (helpProperties.isPresent(args)) { try { printProperties(ctx, getNodeProperties(ctx)); } catch (Exception e) { ctx.printLine("Failed to obtain the list or properties: " + e.getLocalizedMessage()); return; } return; } } catch (CommandFormatException e) { ctx.printLine(e.getLocalizedMessage()); return; } try { if (helpCommands.isPresent(args)) { printCommands(ctx); return; } } catch (CommandFormatException e) { ctx.printLine(e.getLocalizedMessage()); return; } final String operationName = operation.getValue(args); if (operationName == null) { printNodeDescription(ctx); return; } try { ModelNode result = getOperationDescription(ctx, operationName); if (!result.hasDefined("description")) { ctx.printLine("Operation description is not available."); return; } final StringBuilder buf = new StringBuilder(); buf.append("\nDESCRIPTION:\n\n"); buf.append(result.get("description").asString()); ctx.printLine(buf.toString()); if (result.hasDefined("request-properties")) { printProperties(ctx, result.get("request-properties").asPropertyList()); } else { printProperties(ctx, Collections.<Property>emptyList()); } } catch (Exception e) { } }
@Override public Collection<CommandArgument> getArguments(CommandContext ctx) { ParsedCommandLine args = ctx.getParsedCommandLine(); try { if (!name.isValueComplete(args)) { return staticArgs; } } catch (CommandFormatException e) { return Collections.emptyList(); } final String op = operation.getValue(args); return loadArguments(ctx, op).values(); }
protected ModelNode initRequest(CommandContext ctx) { ModelNode request = new ModelNode(); ModelNode address = request.get(Util.ADDRESS); if (ctx.isDomainMode()) { final String profileName = profile.getValue(ctx.getParsedCommandLine()); if (profile == null) { ctx.printLine("--profile argument is required to get the node description."); return null; } address.add(Util.PROFILE, profileName); } for (OperationRequestAddress.Node node : nodePath) { address.add(node.getType(), node.getName()); } address.add(type, "?"); return request; }
protected void printNodeDescription(CommandContext ctx) { final StringBuilder buf = new StringBuilder(); buf.append("\nSYNOPSIS\n\n"); buf.append(commandName).append(" --help [--properties | --commands] |\n"); for (int i = 0; i <= commandName.length(); ++i) { buf.append(' '); } buf.append(name.getFullName()) .append("=<value> --<property>=<value> (--<property>=<value>)* |\n"); for (int i = 0; i <= commandName.length(); ++i) { buf.append(' '); } buf.append("<command> ").append(name.getFullName()).append("=<value> (--<parameter>=<value>)*"); buf.append("\n\nDESCRIPTION\n\n"); buf.append("The command is used to manage resources of type " + this.nodeType + "."); buf.append("\n\nRESOURCE DESCRIPTION\n\n"); if (isDependsOnProfile() && ctx.isDomainMode() && profile.getValue(ctx.getParsedCommandLine()) == null) { buf.append("(Execute '"); buf.append(commandName) .append(" --profile=<profile_name> --help' to include the resource description here.)"); } else { ModelNode request = initRequest(ctx); if (request == null) { return; } request.get(Util.OPERATION).set(Util.READ_RESOURCE_DESCRIPTION); ModelNode result = null; try { result = ctx.getModelControllerClient().execute(request); if (!result.hasDefined(Util.RESULT)) { ctx.error("Node description is not available."); return; } result = result.get(Util.RESULT); if (!result.hasDefined(Util.DESCRIPTION)) { ctx.error("Node description is not available."); return; } } catch (Exception e) { } if (result != null) { buf.append(result.get(Util.DESCRIPTION).asString()); } else { buf.append( "N/A. Please, open a jira issue at https://issues.jboss.org/browse/AS7 to get this fixed. Thanks!"); } } buf.append("\n\nARGUMENTS\n"); buf.append("\n--help - prints this content."); buf.append( "\n--help --properties - prints the list of the resource properties including their access-type"); buf.append("\n (read/write/metric), value type, and the description."); buf.append( "\n--help --commands - prints the list of the commands available for the resource."); buf.append( "\n To get the complete description of a specific command (including its parameters,"); buf.append("\n their types and descriptions), execute ") .append(commandName) .append(" <command> --help."); buf.append("\n\n").append(name.getFullName()).append(" - "); if (idProperty == null) { buf.append("is the name of the resource that completes the path ") .append(nodeType) .append(" and \n"); } else { buf.append("corresponds to a property of the resourse which \n"); } for (int i = 0; i < name.getFullName().length() + 5; ++i) { buf.append(' '); } buf.append("is used to identify the resourse against which the command should be executed."); buf.append("\n\n<property> - property name of the resourse whose value should be updated."); buf.append( "\n For a complete list of available property names, their types and descriptions,"); buf.append("\n execute ").append(commandName).append(" --help --properties."); buf.append( "\n\n<command> - command name provided by the resourse. For a complete list of available commands,"); buf.append("\n execute ").append(commandName).append(" --help --commands."); buf.append("\n\n<parameter> - parameter name of the <command> provided by the resourse."); buf.append( "\n For a complete list of available parameter names of a specific <command>,"); buf.append("\n their types and descriptions, execute ") .append(commandName) .append(" <command> --help."); ctx.printLine(buf.toString()); }