Scan for the first argument with a param name that matches the argname. Scanning for arg "foo" looks for any of "--foo", "--not--foo", "--not-foo", "-foo", "-not--foo", "-not-foo". @param remaining list of remaining args to scan through @param argname argname to scan for, case sensitive @param foun
(List<String> remaining, String argname, boolean foundVal)
| 126 | * or if the flag is not seen, !foundVal will be returned. |
| 127 | */ |
| 128 | public static boolean scanForFlag(List<String> remaining, String argname, boolean foundVal) { |
| 129 | // match --not--arg, or single dash versions |
| 130 | // case sensitive. |
| 131 | Pattern pattern = Pattern.compile(flagPattern(argname)); |
| 132 | Optional<Matcher> got = new ArrayList<>(remaining).stream().map((s) -> { |
| 133 | Matcher ret = match(pattern, s); |
| 134 | if (ret != null) { |
| 135 | remaining.remove(s); |
| 136 | } |
| 137 | return ret; |
| 138 | }).filter(Objects::nonNull).limit(1).reduce((first, second) -> second); |
| 139 | |
| 140 | if (got.isPresent()) { |
| 141 | String not = got.get().group(2); |
| 142 | if (not == null) { |
| 143 | return foundVal; |
| 144 | } else { |
| 145 | return !foundVal; |
| 146 | } |
| 147 | } |
| 148 | return !foundVal; |
| 149 | } |
| 150 | |
| 151 | static class FlagArg { |
| 152 | private final String arg; |