HelpAction extends EndpointsToolAction { @Override public boolean execute() throws ClassNotFoundException, IOException, ApiConfigException { if (getArgs().isEmpty()) { EndpointsTool tool = new EndpointsTool(); tool.printUsage(); return true; } else if (getArgs().size() > 1) { return false; } String commandName = getArgs().get(0); switch (commandName) { case "get-client-lib": printUsage(new GetClientLibAction()); return true; case "get-discovery-doc": printUsage(new GetDiscoveryDocAction()); return true; case "gen-api-config": printUsage(new GenApiConfigAction()); return true; case "gen-client-lib": printUsage(new GenClientLibAction()); return true; default: return false; } } HelpAction(); @Override boolean execute(); @Override String getUsageString(); static final String NAME; }
@Test public void testHelp() throws Exception { tool.execute(new String[]{HelpAction.NAME, "get-client-lib"}); assertTrue(action instanceof GetClientLibAction); tool.execute(new String[]{HelpAction.NAME, "get-discovery-doc"}); assertTrue(action instanceof GetDiscoveryDocAction); }
@Test public void testHelpUnknownAction() throws Exception { tool.execute(new String[]{HelpAction.NAME, "unknown"}); assertTrue(usagePrinted); }
@Test public void testHelpInvisibleAction() throws Exception { tool.execute(new String[]{HelpAction.NAME, "gen-api-config"}); assertTrue(action instanceof GenApiConfigAction); tool.execute(new String[]{HelpAction.NAME, "gen-client-lib"}); assertTrue(action instanceof GenClientLibAction); }