@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 fileDoesNotExist() throws Exception {
    assertThrows(FileNotFoundException.class, () -> {
      List<String> args = Collections.singletonList(new File(temporaryFolder, "nonExistingFile").getAbsolutePath());
      int returnCode = new RecordCountTool().run(System.in, System.out, System.err, args);
      assertEquals(1, returnCode);
    });
  }