/** * Creates a usage string which can be printed in case the user did specify the arguments * incorrectly. Incorrectly is defined as {@link ArgumentParser#validateArguments(String[], Class)} * returns false. * * @param argProxyInterface interface with parameter descriptions * @return the help message usage string */ @SuppressWarnings({"unchecked"}) public static <T> String createUsage(Class<T> argProxyInterface) { return createUsage(new Class[]{argProxyInterface}); }
protected String getBasicHelp(Class<?>... argProxyInterfaces) { return "Usage: " + CLI.CMD + " " + getName() + " " + ArgumentParser.createUsage(argProxyInterfaces); }
@Override protected String getBasicHelp(Class<?>... argProxyInterfaces) { Map<String, ObjectStreamFactory<T>> factories = StreamFactoryRegistry.getFactories(type); String formatsHelp = " "; if (1 < factories.size()) { StringBuilder formats = new StringBuilder(); for (String format : factories.keySet()) { if (!StreamFactoryRegistry.DEFAULT_FORMAT.equals(format)) { formats.append(".").append(format).append("|"); } } formatsHelp = "[" + formats.substring(0, formats.length() - 1) + "] "; } return "Usage: " + CLI.CMD + " " + getName() + formatsHelp + ArgumentParser.createUsage(argProxyInterfaces); }
@Test(expected = IllegalArgumentException.class) public void testInvalidMethodName() { ArgumentParser.createUsage(InvalidMethodName.class); }
@Test(expected = IllegalArgumentException.class) public void testZeroMethods() { ArgumentParser.createUsage(ZeroMethods.class); }
@Test(expected = IllegalArgumentException.class) public void testInvalidReturnType() { ArgumentParser.createUsage(InvalidReturnType.class); }
/** * Validates arguments for a format processed by the <code>factory</code>. * @param factory a stream factory * @param args arguments */ protected void validateFactoryArgs(ObjectStreamFactory<T> factory, String[] args) { String errMessage = ArgumentParser.validateArgumentsLoudly(args, factory.getParameters()); if (null != errMessage) { throw new TerminateToolException(1, "Format parameters are invalid: " + errMessage + "\n" + "Usage: " + ArgumentParser.createUsage(factory.getParameters())); } }
System.arraycopy(args, 1, formatArgs, 0, formatArgs.length); String helpString = createHelpString(format, ArgumentParser.createUsage(streamFactory.getParameters())); if (0 == formatArgs.length || (1 == formatArgs.length && "help".equals(formatArgs[0]))) { System.out.println(helpString);
public String getHelp(String format) { if ("".equals(format) || StreamFactoryRegistry.DEFAULT_FORMAT.equals(format)) { return getBasicHelp(paramsClass, StreamFactoryRegistry.getFactory(type, StreamFactoryRegistry.DEFAULT_FORMAT).getParameters()); } else { ObjectStreamFactory<T> factory = StreamFactoryRegistry.getFactory(type, format); if (null == factory) { throw new TerminateToolException(1, "Format " + format + " is not found.\n" + getHelp()); } return "Usage: " + CLI.CMD + " " + getName() + "." + format + " " + ArgumentParser.createUsage(paramsClass, factory.getParameters()); } } }
@Test public void testSimpleArgumentsUsage() { String[] arguments = new String[] {"-encoding charset", "[-iterations num]", "[-alphaNumOpt true|false]"}; String usage = ArgumentParser.createUsage(SimpleArguments.class); int expectedLength = 2; for (String arg : arguments) { Assert.assertTrue(usage.contains(arg)); expectedLength += arg.length(); } Assert.assertTrue(usage.contains("a charset encoding")); Assert.assertTrue(expectedLength < usage.length()); }
/** * Creates a usage string which can be printed in case the user did specify the arguments * incorrectly. Incorrectly is defined as {@link ArgumentParser#validateArguments(String[], Class)} * returns false. * * @param argProxyInterface interface with parameter descriptions * @return the help message usage string */ @SuppressWarnings({"unchecked"}) public static <T> String createUsage(Class<T> argProxyInterface) { return createUsage(new Class[]{argProxyInterface}); }
/** * Creates a usage string which can be printed in case the user did specify the arguments * incorrectly. Incorrectly is defined as {@link ArgumentParser#validateArguments(String[], Class)} * returns false. * * @param argProxyInterface interface with parameter descriptions * @return the help message usage string */ @SuppressWarnings({"unchecked"}) public static <T> String createUsage(Class<T> argProxyInterface) { return createUsage(new Class[]{argProxyInterface}); }
@Override public String getHelp() { return "Usage: " + CLI.CMD + " " + getName() + " " + ArgumentParser.createUsage(this.paramsClass); }
public String getHelp() { return "Usage: " + CLI.CMD + " " + getName() + " " + ArgumentParser.createUsage(DisambiguatorEvaluatorParams.class); }
public String getHelp() { return "Usage: " + CLI.CMD + " " + getName() + " " + ArgumentParser.createUsage(DisambiguatorToolParams.class) + " < sentences"; }
protected String getBasicHelp(Class<?>... argProxyInterfaces) { return "Usage: " + CLI.CMD + " " + getName() + " " + ArgumentParser.createUsage(argProxyInterfaces); }
protected String getBasicHelp(Class<?>... argProxyInterfaces) { return "Usage: " + CLI.CMD + " " + getName() + " " + ArgumentParser.createUsage(argProxyInterfaces); }
/** * Validates arguments for a format processed by the <code>factory</code>. * @param factory a stream factory * @param args arguments */ protected void validateFactoryArgs(ObjectStreamFactory<T> factory, String[] args) { String errMessage = ArgumentParser.validateArgumentsLoudly(args, factory.getParameters()); if (null != errMessage) { throw new TerminateToolException(1, "Format parameters are invalid: " + errMessage + "\n" + "Usage: " + ArgumentParser.createUsage(factory.getParameters())); } }
/** * Validates arguments for a format processed by the <code>factory</code>. * @param factory a stream factory * @param args arguments */ protected void validateFactoryArgs(ObjectStreamFactory<T> factory, String[] args) { String errMessage = ArgumentParser.validateArgumentsLoudly(args, factory.getParameters()); if (null != errMessage) { throw new TerminateToolException(1, "Format parameters are invalid: " + errMessage + "\n" + "Usage: " + ArgumentParser.createUsage(factory.getParameters())); } }
public String getHelp(String format) { if ("".equals(format) || StreamFactoryRegistry.DEFAULT_FORMAT.equals(format)) { return getBasicHelp(paramsClass, StreamFactoryRegistry.getFactory(type, StreamFactoryRegistry.DEFAULT_FORMAT).getParameters()); } else { ObjectStreamFactory<T> factory = StreamFactoryRegistry.getFactory(type, format); if (null == factory) { throw new TerminateToolException(1, "Format " + format + " is not found.\n" + getHelp()); } return "Usage: " + CLI.CMD + " " + getName() + "." + format + " " + ArgumentParser.createUsage(paramsClass, factory.getParameters()); } } }