Module RargInternal.Type

module 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])

type parse('a) = string => Stdlib.result('a, option(string));
type t('a) = {
name: string,

name of the type that will appear in help

parse: parse('a),

string to type

stringify: 'a => string,

type to string

choices: option(Choices.t('a)),

values to be used in autocompletion and help

};
let make: name:string => parse:parse('a) => stringify:('a => string) => ?⁠choices:Choices.t('a) => unit => t('a);

Creates a reusable Type parser with optional autocomplete suggestions, that you can pass when adding new Args. For example to create a type-safe fruits variant type:

type fruit = | Apple | Banana;
let fruit: Type.t(fruit) = {
  name: "fruit",
  parse:
    fun
    | "apple" => Ok(Apple)
    | "banana" => Ok(Banana)
    | x => Error(Some(x ++ " is not a fruit.")),
  stringify:
    fun
    | Apple => "apple"
    | Banana => "banana",
  choices: Some(HelpAndSuggestions([Apple, Banana])),
};
let withChoices: t('a) => Choices.t('a) => t('a);

Extends an existing type parser with a list of possible choices. For example you can extend the string type to autocomplete the value origin/master with:

withChoices(string, Suggestions(["origin/master"]))
let with_choices: t('a) => Choices.t('a) => t('a);

(alias of withChoices) Extends an existing type parser with a list of possible choices For example a string parser can be extended to suggest the values "apple" and "banana"

let char: t(char);

Predefined basic type parsers

let string: t(string);
let int: t(int);
let float: t(float);
let bool: t(bool);

bool type (parses only true/false, check flag for parsing truthy/falsey values)

let shell: t(Seed.Process.Shell.t);

Parses shell values like bash or zsh

let flag: t(bool);

Parses truthy/falsey values like true/false on/off yes/no y/n and 1/0

let branch: t(string);

Autosuggests git branches (without validating them)