@Test public void withDirectoryOnly() throws ParseException { String[] argv = givenInputOptions("./dir"); ToolOptions options = parser.parse(argv); assertEqualOptions(options, expected() .withPath(Paths.get("./dir"))); }
ToolOptions parse(String... argv) throws ParseException { CommandLine cmd = new DefaultParser().parse(getCmdLineOptions(), argv, false); ToolOptions.Builder optionsBuilder = ToolOptions.builder(); if (cmd.hasOption(HELP_OPTION)) { return optionsBuilder .withHelp(true) .build(); } parseFollowOption(cmd).ifPresent(optionsBuilder::withFollow); parseLongOption(cmd, LIMIT_OPTION).ifPresent(optionsBuilder::withLimit); parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withTail); parseRollCycleOption(cmd).ifPresent(optionsBuilder::withRollCycle); parseConfigPathOption(cmd).ifPresent(optionsBuilder::withConfig); optionsBuilder.withPath(parsePath(cmd)); if (noFollowOrExplicitLimit(cmd)) { parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withLimit); } return optionsBuilder.build(); }
OptionParser { ToolOptions parse(String... argv) throws ParseException { CommandLine cmd = new DefaultParser().parse(getCmdLineOptions(), argv, false); ToolOptions.Builder optionsBuilder = ToolOptions.builder(); if (cmd.hasOption(HELP_OPTION)) { return optionsBuilder .withHelp(true) .build(); } parseFollowOption(cmd).ifPresent(optionsBuilder::withFollow); parseLongOption(cmd, LIMIT_OPTION).ifPresent(optionsBuilder::withLimit); parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withTail); parseRollCycleOption(cmd).ifPresent(optionsBuilder::withRollCycle); parseConfigPathOption(cmd).ifPresent(optionsBuilder::withConfig); optionsBuilder.withPath(parsePath(cmd)); if (noFollowOrExplicitLimit(cmd)) { parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withLimit); } return optionsBuilder.build(); } }
OptionParser { ToolOptions parse(String... argv) throws ParseException { CommandLine cmd = new DefaultParser().parse(getCmdLineOptions(), argv, false); ToolOptions.Builder optionsBuilder = ToolOptions.builder(); if (cmd.hasOption(HELP_OPTION)) { return optionsBuilder .withHelp(true) .build(); } parseFollowOption(cmd).ifPresent(optionsBuilder::withFollow); parseLongOption(cmd, LIMIT_OPTION).ifPresent(optionsBuilder::withLimit); parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withTail); parseRollCycleOption(cmd).ifPresent(optionsBuilder::withRollCycle); parseConfigPathOption(cmd).ifPresent(optionsBuilder::withConfig); optionsBuilder.withPath(parsePath(cmd)); if (noFollowOrExplicitLimit(cmd)) { parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withLimit); } return optionsBuilder.build(); }  }
OptionParser { ToolOptions parse(String... argv) throws ParseException { CommandLine cmd = new DefaultParser().parse(getCmdLineOptions(), argv, false); ToolOptions.Builder optionsBuilder = ToolOptions.builder(); if (cmd.hasOption(HELP_OPTION)) { return optionsBuilder .withHelp(true) .build(); } parseFollowOption(cmd).ifPresent(optionsBuilder::withFollow); parseLongOption(cmd, LIMIT_OPTION).ifPresent(optionsBuilder::withLimit); parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withTail); parseRollCycleOption(cmd).ifPresent(optionsBuilder::withRollCycle); parseConfigPathOption(cmd).ifPresent(optionsBuilder::withConfig); optionsBuilder.withPath(parsePath(cmd)); if (noFollowOrExplicitLimit(cmd)) { parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withLimit); } return optionsBuilder.build(); }   }
OptionParser { ToolOptions parse(String... argv) throws ParseException { CommandLine cmd = new DefaultParser().parse(getCmdLineOptions(), argv, false); ToolOptions.Builder optionsBuilder = ToolOptions.builder(); if (cmd.hasOption(HELP_OPTION)) { return optionsBuilder .withHelp(true) .build(); } parseFollowOption(cmd).ifPresent(optionsBuilder::withFollow); parseLongOption(cmd, LIMIT_OPTION).ifPresent(optionsBuilder::withLimit); parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withTail); parseRollCycleOption(cmd).ifPresent(optionsBuilder::withRollCycle); parseConfigPathOption(cmd).ifPresent(optionsBuilder::withConfig); optionsBuilder.withPath(parsePath(cmd)); if (noFollowOrExplicitLimit(cmd)) { parseLongOption(cmd, TAIL_OPTION).ifPresent(optionsBuilder::withLimit); } return optionsBuilder.build(); }    }