HelpfulOptions.Other (helpful_options v0.3.1)

Summary

Functions

You can specify how many other parameters are required

Types

Link to this type

other_options()

@type other_options() ::
  %{min: non_neg_integer(), max: non_neg_integer()}
  | %{min: non_neg_integer()}
  | %{max: non_neg_integer()}
  | non_neg_integer()
@type t() :: other_options() | :any | nil

Functions

Link to this function

check(other, required)

@spec check([String.t()], t()) :: {:ok} | {:error, HelpfulOptions.Errors.t()}

You can specify how many other parameters are required:

iex> HelpfulOptions.Other.check(["first", "second"], 2)
{:ok}

You can indicate limits with :min and/or :max:

iex> HelpfulOptions.Other.check(["first", "second"], %{min: 2, max: 3})
{:ok}

Alternatively, you can accept any number of other parameters with :any:

iex> HelpfulOptions.Other.check(["first", "second"], :any)
{:ok}

It's an error if you specify a count and the wrong number of other parameters is supplied:

iex> HelpfulOptions.Other.check(["first"], 2)
{:error, %HelpfulOptions.OtherErrors{required: 2, actual: 1}}

It's also an error if other parameters are supplied when none were specified:

iex> HelpfulOptions.Other.check(["pizza"], nil)
{:error, %HelpfulOptions.OtherErrors{unexpected: ["pizza"]}}

Or, if they are outside the indicated range:

iex> HelpfulOptions.Other.check(["first"], %{min: 2, max: 3})
{:error, %HelpfulOptions.OtherErrors{max: 3, min: 2, actual: 1}}