EndpointsToolAction extends Action { @Override protected List<String> getHelpLines() { ImmutableList.Builder<String> helpLines = ImmutableList.builder(); helpLines.add(getNameString()); helpLines.add(""); helpLines.addAll(wrap(getShortDescription(), MAX_WIDTH, 0)); helpLines.add(""); helpLines.add("Usage: <Endpoints tool> " + getUsageString()); if (getOptions().size() > 0) { helpLines.add(""); helpLines.add("Options:"); for (Option option : getOptions()) { for (String optionHelpLine : option.getHelpLines()) { helpLines.add(Strings.repeat(" ", OPTION_INDENT) + optionHelpLine); } } } helpLines.add(""); if (!Strings.isNullOrEmpty(exampleString)) { helpLines.add("Example:"); helpLines.add(" " + exampleString); helpLines.add(""); } return helpLines.build(); } EndpointsToolAction(String name); abstract String getUsageString(); abstract boolean execute(); @Override void apply(); boolean isHelpDisplayNeeded(); void setHelpDisplayNeeded(boolean helpDisplayNeeded); String getExampleString(); void setExampleString(String exampleString); static final String OPTION_CLASS_PATH_SHORT; static final String OPTION_CLASS_PATH_LONG; static final String OPTION_OUTPUT_DIR_SHORT; static final String OPTION_OUTPUT_DIR_LONG; static final String OPTION_WAR_SHORT; static final String OPTION_WAR_LONG; static final String OPTION_LANGUAGE_SHORT; static final String OPTION_LANGUAGE_LONG; static final String OPTION_BUILD_SYSTEM_SHORT; static final String OPTION_BUILD_SYSTEM_LONG; static final String OPTION_FORMAT_SHORT; static final String OPTION_FORMAT_LONG; static final String OPTION_DEBUG; static final String OPTION_HOSTNAME_SHORT; static final String OPTION_HOSTNAME_LONG; static final String OPTION_BASE_PATH_SHORT; static final String OPTION_BASE_PATH_LONG; }
@Test public void testGetHelpLines() { TestAction action = new TestAction() { @Override public List<Option> getOptions() { return ImmutableList.<Option>of( EndpointsOption.makeVisibleNonFlagOption( "t", "test", "TEST", "This is a totally meaningless description, which is used to test output of " + "helpLines() method.")); } }; assertTrue(action.isHelpDisplayNeeded()); List<String> expectedLines = ImmutableList.of( "test", "", "This is an Endpoints tool action for junit tests.", "", "Usage: <Endpoints tool> test <OPTIONS>", "", "Options:", " -t TEST, --test=TEST", " This is a totally meaningless description, which is used to test output of", " helpLines() method.", "", "Example:", " <Endpoints tool> --option=option test", ""); assertEquals(expectedLines, action.getHelpLines()); }
@Test public void testEndpointsOption() { EndpointsOption testOption = EndpointsOption.makeVisibleNonFlagOption("t", "test", "TEST_VALUE", "test description"); assertEquals("t", testOption.getShortName()); assertEquals("test", testOption.getLongName()); assertTrue(!testOption.isFlag()); List<String> expectedLines = ImmutableList.of( "-t TEST_VALUE, --test=TEST_VALUE", " test description"); assertEquals(expectedLines, testOption.getHelpLines()); }