@Test(expected = FluoCommandException.class) public void testExecutionError() { mockFluoCommand.throwException = true; FluoProgram.runFluoCommand(Collections.singletonList(mockFluoCommand), new String[] {"test"}); }
public static void runFluoCommand(List<FluoCommand> fluoCommands, String[] args) { JCommander.Builder jCommanderBuilder = JCommander.newBuilder(); fluoCommands.forEach(jCommanderBuilder::addCommand); JCommander jcommand = jCommanderBuilder.build(); try { jcommand.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); String commandName = Optional.ofNullable(jcommand.getParsedCommand()).orElse(""); JCommander parsedJCommandOrProgram = Optional.ofNullable(jcommand.findCommandByAlias(commandName)).orElse(jcommand); parsedJCommandOrProgram.setProgramName(String.format("fluo %s", commandName)); parsedJCommandOrProgram.usage(); throw e; } String parsedCommandType = jcommand.getParsedCommand(); JCommander parsedJCommand = jcommand.findCommandByAlias(parsedCommandType); String programName = String.format("fluo %s", parsedCommandType); parsedJCommand.setProgramName(programName); FluoCommand parsedFluoCommand = (FluoCommand) Iterables.getOnlyElement(parsedJCommand.getObjects()); if (parsedFluoCommand.isHelp()) { parsedJCommand.usage(); return; } try { parsedFluoCommand.execute(); } catch (FluoCommandException e) { System.err.println(String.format("%s failed - %s", programName, e.getMessage())); throw e; } }
FluoProgram { public static void runFluoCommand(List<FluoCommand> fluoCommands, String[] args) { JCommander.Builder jCommanderBuilder = JCommander.newBuilder(); fluoCommands.forEach(jCommanderBuilder::addCommand); JCommander jcommand = jCommanderBuilder.build(); try { jcommand.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); String commandName = Optional.ofNullable(jcommand.getParsedCommand()).orElse(""); JCommander parsedJCommandOrProgram = Optional.ofNullable(jcommand.findCommandByAlias(commandName)).orElse(jcommand); parsedJCommandOrProgram.setProgramName(String.format("fluo %s", commandName)); parsedJCommandOrProgram.usage(); throw e; } String parsedCommandType = jcommand.getParsedCommand(); JCommander parsedJCommand = jcommand.findCommandByAlias(parsedCommandType); String programName = String.format("fluo %s", parsedCommandType); parsedJCommand.setProgramName(programName); FluoCommand parsedFluoCommand = (FluoCommand) Iterables.getOnlyElement(parsedJCommand.getObjects()); if (parsedFluoCommand.isHelp()) { parsedJCommand.usage(); return; } try { parsedFluoCommand.execute(); } catch (FluoCommandException e) { System.err.println(String.format("%s failed - %s", programName, e.getMessage())); throw e; } } }
FluoProgram { public static void runFluoCommand(List<FluoCommand> fluoCommands, String[] args) { JCommander.Builder jCommanderBuilder = JCommander.newBuilder(); fluoCommands.forEach(jCommanderBuilder::addCommand); JCommander jcommand = jCommanderBuilder.build(); try { jcommand.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); String commandName = Optional.ofNullable(jcommand.getParsedCommand()).orElse(""); JCommander parsedJCommandOrProgram = Optional.ofNullable(jcommand.findCommandByAlias(commandName)).orElse(jcommand); parsedJCommandOrProgram.setProgramName(String.format("fluo %s", commandName)); parsedJCommandOrProgram.usage(); throw e; } String parsedCommandType = jcommand.getParsedCommand(); JCommander parsedJCommand = jcommand.findCommandByAlias(parsedCommandType); String programName = String.format("fluo %s", parsedCommandType); parsedJCommand.setProgramName(programName); FluoCommand parsedFluoCommand = (FluoCommand) Iterables.getOnlyElement(parsedJCommand.getObjects()); if (parsedFluoCommand.isHelp()) { parsedJCommand.usage(); return; } try { parsedFluoCommand.execute(); } catch (FluoCommandException e) { System.err.println(String.format("%s failed - %s", programName, e.getMessage())); throw e; } }  }
FluoProgram { public static void runFluoCommand(List<FluoCommand> fluoCommands, String[] args) { JCommander.Builder jCommanderBuilder = JCommander.newBuilder(); fluoCommands.forEach(jCommanderBuilder::addCommand); JCommander jcommand = jCommanderBuilder.build(); try { jcommand.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); String commandName = Optional.ofNullable(jcommand.getParsedCommand()).orElse(""); JCommander parsedJCommandOrProgram = Optional.ofNullable(jcommand.findCommandByAlias(commandName)).orElse(jcommand); parsedJCommandOrProgram.setProgramName(String.format("fluo %s", commandName)); parsedJCommandOrProgram.usage(); throw e; } String parsedCommandType = jcommand.getParsedCommand(); JCommander parsedJCommand = jcommand.findCommandByAlias(parsedCommandType); String programName = String.format("fluo %s", parsedCommandType); parsedJCommand.setProgramName(programName); FluoCommand parsedFluoCommand = (FluoCommand) Iterables.getOnlyElement(parsedJCommand.getObjects()); if (parsedFluoCommand.isHelp()) { parsedJCommand.usage(); return; } try { parsedFluoCommand.execute(); } catch (FluoCommandException e) { System.err.println(String.format("%s failed - %s", programName, e.getMessage())); throw e; } }  static void main(String[] args); static void runFluoCommand(List<FluoCommand> fluoCommands, String[] args); }
FluoProgram { public static void runFluoCommand(List<FluoCommand> fluoCommands, String[] args) { JCommander.Builder jCommanderBuilder = JCommander.newBuilder(); fluoCommands.forEach(jCommanderBuilder::addCommand); JCommander jcommand = jCommanderBuilder.build(); try { jcommand.parse(args); } catch (ParameterException e) { System.err.println(e.getMessage()); String commandName = Optional.ofNullable(jcommand.getParsedCommand()).orElse(""); JCommander parsedJCommandOrProgram = Optional.ofNullable(jcommand.findCommandByAlias(commandName)).orElse(jcommand); parsedJCommandOrProgram.setProgramName(String.format("fluo %s", commandName)); parsedJCommandOrProgram.usage(); throw e; } String parsedCommandType = jcommand.getParsedCommand(); JCommander parsedJCommand = jcommand.findCommandByAlias(parsedCommandType); String programName = String.format("fluo %s", parsedCommandType); parsedJCommand.setProgramName(programName); FluoCommand parsedFluoCommand = (FluoCommand) Iterables.getOnlyElement(parsedJCommand.getObjects()); if (parsedFluoCommand.isHelp()) { parsedJCommand.usage(); return; } try { parsedFluoCommand.execute(); } catch (FluoCommandException e) { System.err.println(String.format("%s failed - %s", programName, e.getMessage())); throw e; } }  static void main(String[] args); static void runFluoCommand(List<FluoCommand> fluoCommands, String[] args);  }