CommandLineUsage { public static String getUsageTextForOperator(String operatorName) { final OperatorSpi operatorSpi = GPF.getDefaultInstance().getOperatorSpiRegistry().getOperatorSpi(operatorName); if (operatorSpi == null) { return MessageFormat.format("Unknown operator ''{0}''.", operatorName); } OperatorDescriptor operatorDescriptor = operatorSpi.getOperatorDescriptor(); StringBuilder usageText = new StringBuilder(1024); usageText.append("Usage:\n"); usageText.append(MessageFormat.format(" {0} {1} [options] ", CommandLineTool.TOOL_NAME, operatorName)); ArrayList<DocElement> sourceDocElementList = createSourceDocElementList(operatorDescriptor); ArrayList<DocElement> paramDocElementList = createParamDocElementList(operatorDescriptor); ArrayList<DocElement> propertyDocElementList = createPropertyDocElementList(operatorDescriptor); final SourceProductsDescriptor productsDescriptor = operatorDescriptor.getSourceProductsDescriptor(); if (productsDescriptor != null) { appendSourceFiles(usageText, productsDescriptor); } usageText.append("\n"); if (operatorDescriptor.getDescription() != null) { usageText.append("\nDescription:\n"); final String description = operatorDescriptor.getDescription(); final String[] lines = description.split("\n"); for (String line : lines) { usageText.append(" "); usageText.append(line); usageText.append("\n"); } } if (!propertyDocElementList.isEmpty()) { usageText.append("\nComputed Properties:\n"); appendDocElementList(usageText, propertyDocElementList); } usageText.append("\n"); if (!sourceDocElementList.isEmpty()) { usageText.append("\nSource Options:\n"); appendDocElementList(usageText, sourceDocElementList); } if (!paramDocElementList.isEmpty()) { usageText.append("\nParameter Options:\n"); appendDocElementList(usageText, paramDocElementList); } usageText.append("\nGraph XML Format:\n"); appendXmlUsage(usageText, operatorDescriptor); return usageText.toString(); }  static String getUsageText(); static String getUsageTextForGraph(String path, CommandLineContext commandLineContext); static String getUsageTextForOperator(String operatorName);  }
@Test public void testOperatorUsageText() throws NoSuchFieldException { String usageText = CommandLineUsage.getUsageTextForOperator("FooOp"); Assert.assertEquals("Usage:\n" + " gpt FooOp [options] \n" + "\n" + "\n" + "Source Options:\n" + " -Sinput1=<file> Sets source 'input1' to <filepath>.\n" + " This is a mandatory source.\n" + " -Sinput2=<file> Sets source 'input2' to <filepath>.\n" + " This is a mandatory source.\n" + "\n" + "Parameter Options:\n" + " -Py=<string> Sets parameter 'y' to <string>.\n" + " -Pz=<float> Sets parameter 'z' to <float>.\n" + "\n" + "Graph XML Format:\n" + " <graph id=\"someGraphId\">\n" + " <version>1.0</version>\n" + " <node id=\"someNodeId\">\n" + " <operator>FooOp</operator>\n" + " <sources>\n" + " <input1>${input1}</input1>\n" + " <input2>${input2}</input2>\n" + " </sources>\n" + " <parameters>\n" + " <z>float</z>\n" + " <y>string</y>\n" + " <bar>\n" + " <c>float</c>\n" + " <b>string</b>\n" + " </bar>\n" + " </parameters>\n" + " </node>\n" + " </graph>\n", usageText); }