@Override
  public int run(InputStream stdin, PrintStream out, PrintStream err, List<String> args) throws Exception {
    OptionParser optionParser = new OptionParser();
    OptionSet optionSet = optionParser.parse(args.toArray(new String[0]));
    List<String> nargs = (List<String>) optionSet.nonOptionArguments();

    if (nargs.isEmpty()) {
      printHelp(err);
      err.println();
      optionParser.printHelpOn(err);
      return 0;
    }

    long count = 0L;
    if (ImmutableList.of("-").equals(nargs)) {
      count = countRecords(stdin);
    } else {
      for (Path file : Util.getFiles(nargs)) {
        try (final InputStream inStream = Util.openFromFS(file)) {
          count += countRecords(inStream);
        }
      }
    }
    out.println(count);
    out.flush();
    return 0;
  }
@Test
  void multipleFiles() throws Exception {
    File f1 = generateData(20);
    File f2 = generateData(200);

    List<String> args = Arrays.asList(f1.getAbsolutePath(), f2.getAbsolutePath());
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    int returnCode = new RecordCountTool().run(System.in, new PrintStream(out), System.err, args);

    assertEquals(0, returnCode);
    assertEquals("220" + System.lineSeparator(), out.toString());
  }