Param
single : DefaultableParameterConfigParams data -> CliBuilder data {}action GetParamsAction
Add a required parameter of a custom type to your CLI builder.
You need to provide a kebab-case type name for your help messages as well as a
parser for said type. The parser needs to return an Err (InvalidValue Str)
on failure, where the Str
is the reason the parsing failed that will
get displayed in the incorrect usage message.
Parsing arguments will fail if the parameter fails to parse or is not provided.
Parameters must be provided last after any option or subcommand fields,
as they are parsed last of the three extracted values, and parameter
list fields cannot be followed by any other fields. This is enforced
using the type state pattern, where we encode the state of the program
into its types. If you're curious, check the internal Builder
module to see how this works using the action
type variable.
expect Color : [Green, Red, Blue] parse_color : Arg -> Result Color [InvalidValue Str, InvalidUtf8] parse_color = \color -> when Arg.to_str color is Ok "green" -> Ok Green Ok "red" -> Ok Red Ok "blue" -> Ok Blue other -> Err (InvalidValue "'$(other)' is not a valid color, must be green, red, or blue") { parser } = Param.single { name: "answer", type: "color", parser: parse_color }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "blue"] == SuccessfullyParsed Blue
maybe : ParameterConfigParams data -> CliBuilder (Result data [NoValue]) {}action GetParamsAction
Add an optional parameter of a custom type to your CLI builder.
You need to provide a kebab-case type name for your help messages as well as a
parser for said type. The parser needs to return an Err (InvalidValue Str)
on failure, where the Str
is the reason the parsing failed that will
get displayed in the incorrect usage message.
Parsing arguments will fail if the parameter fails to parse.
Parameters must be provided last after any option or subcommand fields,
as they are parsed last of the three extracted values, and parameter
list fields cannot be followed by any other fields. This is enforced
using the type state pattern, where we encode the state of the program
into its types. If you're curious, check the internal Builder
module to see how this works using the action
type variable.
expect Color : [Green, Red, Blue] parse_color : Arg -> Result Color [InvalidValue Str, InvalidUtf8] parse_color = \color -> when Arg.to_str color is Ok "green" -> Ok Green Ok "red" -> Ok Red Ok "blue" -> Ok Blue other -> Err (InvalidValue "'$(other)' is not a valid color, must be green, red, or blue") { parser } = Param.maybe { name: "answer", type: "color", parser: parse_color }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
list : ParameterConfigParams data -> CliBuilder (List data) {}action StopCollectingAction
Add a parameter of a custom type that can be provided multiple times to your CLI builder.
You need to provide a kebab-case type name for your help messages as well as a
parser for said type. The parser needs to return an Err (InvalidValue Str)
on failure, where the Str
is the reason the parsing failed that will
get displayed in the incorrect usage message.
Parsing arguments will fail if any of the values fail to parse.
Parameters must be provided last after any option or subcommand fields,
as they are parsed last of the three extracted values, and parameter
list fields cannot be followed by any other fields. This is enforced
using the type state pattern, where we encode the state of the program
into its types. If you're curious, check the internal Builder
module to see how this works using the action
type variable.
expect Color : [Green, Red, Blue] parse_color : Arg -> Result Color [InvalidValue Str, InvalidUtf8] parse_color = \color -> when Arg.to_str color is Ok "green" -> Ok Green Ok "red" -> Ok Red Ok "blue" -> Ok Blue other -> Err (InvalidValue "'$(other)' is not a valid color, must be green, red, or blue") { parser } = Param.list { name: "answer", type: "color", parser: parse_color }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "blue", "red", "green"] == SuccessfullyParsed [Blue, Red, Green]
arg : DefaultableParameterConfigBaseParams Arg -> CliBuilder Arg {}action GetParamsAction
Add a required Arg
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided.
expect { parser } = Param.arg { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "abc"] == SuccessfullyParsed (Arg.from_str "abc")
maybe_arg : ParameterConfigBaseParams -> CliBuilder ArgValue {}action GetParamsAction
Add an optional Arg
parameter to your CLI builder.
Parsing arguments cannot fail because of this parameter.
expect { parser } = Param.maybe_arg { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
arg_list : ParameterConfigBaseParams -> CliBuilder (List Arg) {}action StopCollectingAction
Add an Arg
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments cannot fail because of this parameter.
expect { parser } = Param.arg_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "abc", "def", "ghi"] == SuccessfullyParsed (List.map ["abc", "def", "ghi"] Arg.from_str)
bytes : DefaultableParameterConfigBaseParams (List U8) -> CliBuilder (List U8) {}action GetParamsAction
Add a required byte list parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided.
expect { parser } = Param.arg { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "abc"] == SuccessfullyParsed [97, 98, 99]
maybe_bytes : ParameterConfigBaseParams -> CliBuilder (Result (List U8) [NoValue]) {}action GetParamsAction
Add an optional byte list parameter to your CLI builder.
Parsing arguments cannot fail because of this parameter.
expect { parser } = Param.maybe_bytes { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
bytes_list : ParameterConfigBaseParams -> CliBuilder (List (List U8)) {}action StopCollectingAction
Add a byte list parameter that can be provided multiple times to your CLI builder.
Parsing arguments cannot fail because of this parameter.
expect { parser } = Param.bytes_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "abc", "def", "ghi"] == SuccessfullyParsed [[97, 98, 99], [100, 101, 102], [103, 104, 105]]
str : DefaultableParameterConfigBaseParams Str -> CliBuilder Str {}action GetParamsAction
Add a required string parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or if it is not valid UTF-8.
expect { parser } = Param.str { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "abc"] == SuccessfullyParsed "abc"
maybe_str : ParameterConfigBaseParams -> CliBuilder (Result Str [NoValue]) {}action GetParamsAction
Add an optional string parameter to your CLI builder.
Parsing arguments will fail if the parameter is not valid UTF-8.
expect { parser } = Param.maybe_str { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
str_list : ParameterConfigBaseParams -> CliBuilder (List Str) {}action StopCollectingAction
Add a string parameter that can be provided multiple times to your CLI builder.
Parsing arguments will fail if any of the arguments are not valid UTF-8.
expect { parser } = Param.str_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "abc", "def", "ghi"] == SuccessfullyParsed ["abc", "def", "ghi"]
dec : DefaultableParameterConfigBaseParams Dec -> CliBuilder Dec {}action GetParamsAction
Add a required Dec
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.dec { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42.5"] == SuccessfullyParsed 42.5
maybe_dec : ParameterConfigBaseParams -> CliBuilder (Result Dec [NoValue]) {}action GetParamsAction
Add an optional Dec
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_dec { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
dec_list : ParameterConfigBaseParams -> CliBuilder (List Dec) {}action StopCollectingAction
Add a Dec
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.dec_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "--", "-56.0"] == SuccessfullyParsed [12.0, 34.0, -56.0]
f32 : DefaultableParameterConfigBaseParams F32 -> CliBuilder F32 {}action GetParamsAction
Add a required F32
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.f32 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42.5"] == SuccessfullyParsed 42.5
maybe_f32 : ParameterConfigBaseParams -> CliBuilder (Result F32 [NoValue]) {}action GetParamsAction
Add an optional F32
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_f32 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
f32_list : ParameterConfigBaseParams -> CliBuilder (List F32) {}action StopCollectingAction
Add a F32
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.f32_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "--", "-56.0"] == SuccessfullyParsed [12.0, 34.0, -56.0]
f64 : DefaultableParameterConfigBaseParams F64 -> CliBuilder F64 {}action GetParamsAction
Add a required F64
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.f64 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42.5"] == SuccessfullyParsed 42.5
maybe_f64 : ParameterConfigBaseParams -> CliBuilder (Result F64 [NoValue]) {}action GetParamsAction
Add an optional F64
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_f64 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
f64_list : ParameterConfigBaseParams -> CliBuilder (List F64) {}action StopCollectingAction
Add a F64
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.f64_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "--", "-56.0"] == SuccessfullyParsed [12, 34, -56.0]
u8 : DefaultableParameterConfigBaseParams U8 -> CliBuilder U8 {}action GetParamsAction
Add a required U8
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.u8 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_u8 : ParameterConfigBaseParams -> CliBuilder (Result U8 [NoValue]) {}action GetParamsAction
Add an optional U8
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_u8 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
u8_list : ParameterConfigBaseParams -> CliBuilder (List U8) {}action StopCollectingAction
Add a U8
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.u8_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "56"] == SuccessfullyParsed [12, 34, 56]
u16 : DefaultableParameterConfigBaseParams U16 -> CliBuilder U16 {}action GetParamsAction
Add a required U16
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.u16 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_u16 : ParameterConfigBaseParams -> CliBuilder (Result U16 [NoValue]) {}action GetParamsAction
Add an optional U16
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_u16 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
u16_list : ParameterConfigBaseParams -> CliBuilder (List U16) {}action StopCollectingAction
Add a U16
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.u16_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "56"] == SuccessfullyParsed [12, 34, 56]
u32 : DefaultableParameterConfigBaseParams U32 -> CliBuilder U32 {}action GetParamsAction
Add a required U32
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.u32 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_u32 : ParameterConfigBaseParams -> CliBuilder (Result U32 [NoValue]) {}action GetParamsAction
Add an optional U32
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_u32 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
u32_list : ParameterConfigBaseParams -> CliBuilder (List U32) {}action StopCollectingAction
Add a U32
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.u32_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "56"] == SuccessfullyParsed [12, 34, 56]
u64 : DefaultableParameterConfigBaseParams U64 -> CliBuilder U64 {}action GetParamsAction
Add a required U64
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.u64 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_u64 : ParameterConfigBaseParams -> CliBuilder (Result U64 [NoValue]) {}action GetParamsAction
Add an optional U64
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_u64 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
u64_list : ParameterConfigBaseParams -> CliBuilder (List U64) {}action StopCollectingAction
Add a U64
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.u64_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "56"] == SuccessfullyParsed [12, 34, 56]
u128 : DefaultableParameterConfigBaseParams U128 -> CliBuilder U128 {}action GetParamsAction
Add a required U128
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.u128 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_u128 : ParameterConfigBaseParams -> CliBuilder (Result U128 [NoValue]) {}action GetParamsAction
Add an optional U128
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_u128 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
u128_list : ParameterConfigBaseParams -> CliBuilder (List U128) {}action StopCollectingAction
Add a U128
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.u128_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "56"] == SuccessfullyParsed [12, 34, 56]
i8 : DefaultableParameterConfigBaseParams I8 -> CliBuilder I8 {}action GetParamsAction
Add a required I8
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.i8 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_i8 : ParameterConfigBaseParams -> CliBuilder (Result I8 [NoValue]) {}action GetParamsAction
Add an optional I8
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_i8 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
i8_list : ParameterConfigBaseParams -> CliBuilder (List I8) {}action StopCollectingAction
Add an I8
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.i8_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "--", "-56"] == SuccessfullyParsed [12, 34, -56]
i16 : DefaultableParameterConfigBaseParams I16 -> CliBuilder I16 {}action GetParamsAction
Add a required I16
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.i16 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_i16 : ParameterConfigBaseParams -> CliBuilder (Result I16 [NoValue]) {}action GetParamsAction
Add an optional I16
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_i16 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
i16_list : ParameterConfigBaseParams -> CliBuilder (List I16) {}action StopCollectingAction
Add an I16
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.i16_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "--", "-56"] == SuccessfullyParsed [12, 34, -56]
i32 : DefaultableParameterConfigBaseParams I32 -> CliBuilder I32 {}action GetParamsAction
Add a required I32
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.i32 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_i32 : ParameterConfigBaseParams -> CliBuilder (Result I32 [NoValue]) {}action GetParamsAction
Add an optional I32
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_i32 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
i32_list : ParameterConfigBaseParams -> CliBuilder (List I32) {}action StopCollectingAction
Add an I32
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.i32_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "--", "-56"] == SuccessfullyParsed [12, 34, -56]
i64 : DefaultableParameterConfigBaseParams I64 -> CliBuilder I64 {}action GetParamsAction
Add a required I64
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.i64 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_i64 : ParameterConfigBaseParams -> CliBuilder (Result I64 [NoValue]) {}action GetParamsAction
Add an optional I64
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_i64 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
i64_list : ParameterConfigBaseParams -> CliBuilder (List I64) {}action StopCollectingAction
Add an I64
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.i64_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "--", "-56"] == SuccessfullyParsed [12, 34, -56]
i128 : DefaultableParameterConfigBaseParams I128 -> CliBuilder I128 {}action GetParamsAction
Add a required I128
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not provided or it is not a valid number.
expect { parser } = Param.i128 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "42"] == SuccessfullyParsed 42
maybe_i128 : ParameterConfigBaseParams -> CliBuilder (Result I128 [NoValue]) {}action GetParamsAction
Add an optional I128
parameter to your CLI builder.
Parsing arguments will fail if the parameter is not a valid number.
expect { parser } = Param.maybe_i128 { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example"] == SuccessfullyParsed (Err NoValue)
i128_list : ParameterConfigBaseParams -> CliBuilder (List I128) {}action StopCollectingAction
Add an I128
parameter that can be provided multiple times
to your CLI builder.
Parsing arguments will fail if any of the parameters are not valid numbers.
expect { parser } = Param.i128_list { name: "answer" }, |> Cli.finish { name: "example" } |> Cli.assert_valid parser ["example", "12", "34", "--", "-56"] == SuccessfullyParsed [12, 34, -56]