Module Type.Choices

For defining suggested values in a parser. These values appear in autocompletions and the command help. They are not used for validation which should be part of the parsing. For example you can define static suggestions: Choices.HelpAndSuggestions([Apple, Banana])

Or you can define dynamic autocomplete suggestions that depend on any of the provided arguments so far:

let carModel =
  withChoices(
    string,
    Dynamic(
      (argsMap, _) =>
        switch (getCar(argsMap)) {
        | car =>
          switch (car) {
          | "alfa" => ["4C"]
          | "bmw" => ["3-series", "5-series"]
          | _ => []
          }
        // suggestions are called before input validation
        // -> getCar is not safe to call, so we return an empty list
        // when suggestions are requested, but we don't have a valid car yet
        | exception _e => []
        },
    ),
  );
type argsMap = ArgsMap.t;
type t('a) =
| HelpAndSuggestions(list('a))

The values will appear in both help text and suggestions

| Suggestions(list('a))

The values will appear only in suggestions

| Dynamic(argsMap => (string, array(string)) => list('a))

The values will appear only in suggestions

;
let map: t('a) => ('a => 'b) => t('b);