code: private static CompletionProvider optionCompletion(CompletionProvider provider) {
          return (code, cursor, anchor) -> {
              Matcher ovm = OPTION_VALUE_PATTERN.matcher(code);
              if (ovm.matches()) {
                  String flag = ovm.group("flag");
                  List<CompletionProvider> ps = ARG_OPTIONS.entrySet().stream()
                          .filter(es -> es.getKey().startsWith(flag))
                          .map(es -> es.getValue())
                          .collect(toList());
                  if (ps.size() == 1) {
                      int pastSpace = ovm.start("val");
                      List<Suggestion> result = ps.get(0).completionSuggestions(
                              ovm.group("val"), cursor - pastSpace, anchor);
                      anchor[0] += pastSpace;
                      return result;
                  }
              }
              Matcher om = OPTION_PATTERN.matcher(code);
              if (om.matches()) {
                  int pastSpace = om.start("flag");
                  List<Suggestion> result = provider.completionSuggestions(
                          om.group("flag"), cursor - pastSpace, anchor);
                  if (!om.group("dd").isEmpty()) {
                      result = result.stream()
                              .map(sug -> new Suggestion() {
                                  @Override
                                  public String continuation() {
                                      return "-" + sug.continuation();
                                  }
  
                                  @Override
                                  public boolean matchesType() {
                                      return false;
                                  }
                              })
                              .collect(toList());
                      --pastSpace;
                  }
                  anchor[0] += pastSpace;
                  return result;
              }
              Matcher opp = OPTION_PRE_PATTERN.matcher(code);
              if (opp.matches()) {
                  int pastSpace = opp.end();
                  List<Suggestion> result = provider.completionSuggestions(
                          "", cursor - pastSpace, anchor);
                  anchor[0] += pastSpace;
                  return result;
              }
              return Collections.emptyList();
          };
      }
docs: command-line-like option completion -- options with values