Hey there,
I’ve just released v0.2.0 of Optium, a tiny library for validating options passed in keyword lists.
tl;dr
Github
Documentation
Optium lets you define a “schema” for the options, specifying which of them are required (yep, required option…), selecting the default values and providing validation functions. For example:
schema = %{port: [required: true, validator: &is_integer/1],
address: [required: true, default: {0, 0, 0, 0}]}
iex> [port: 12_345] |> Optium.parse(schema)
{:ok, [port: 12_345, address: {0, 0, 0, 0}]}
iex> [port: 12_345, address: {127, 0, 0, 1}] |> Optium.parse(schema)
{:ok, [port: 12_345, address: {127, 0, 0, 1}]}
iex> [address: {127, 0, 0, 1}] |> Optium.parse(schema)
{:error, Optium.OptionMissingError{keys: [:port]}}
iex> [port: "12_345"] |> Optium.parse(schema)
{:error, %Optium.OptionInvalidError{keys: [:port]}}
And that’s basically all its capable of now. Feedback is very welcome