This commit is contained in:
2026-07-14 22:50:46 +04:00
parent 27143319e3
commit bd19e0682b
3116 changed files with 467189 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

Binary file not shown.

View File

@@ -0,0 +1,98 @@
# Changelog
## v1.1.1 (2024-05-25)
* Fix typespecs to avoid Dialyzer warnings
* Do not list default values as part of received options
* Mark structs in backticks for doc references
* List deprecations in docs
## v1.1.0 (2023-12-13)
* Add a `:type_spec` option to specify a quoted type spec for options.
## v1.0.2 (2023-04-21)
* Improve typespec generation for ranges and structs.
## v1.0.1 (2023-03-13)
* Make the `NimbleOptions.t/0` type *public* (instead of opaque). This helps with Dialyzer issues when ysing `NimbleOptions.new!/1` at compile time.
## v1.0.0 (2023-03-08)
* Add support for a `{:struct, struct_name}` type specifier
* Add support for the `:type_doc` option
* Turn `t:NimbleOptions.t/0` into an *opaque* type
## v0.5.1 (2020-11-05)
* Support generating typespecs for `:tuple`, `:map`, and `{:map, key, value}` options
## v0.5.0 (2020-09-20)
* Support `:map` which accepts the same `:keys` specification as keyword lists
* Normalize all error messages to include the key and expected value out of the box
* Do not nest options when rendered in Markdown and make sure multiline content is properly indented
* Handle \r\n style of line breaks in docs
* Automatically add types to generated docs
* Support lists of keyword lists in `:list`
* Add the `:reference` option type
* Add the `:tuple` option type
## v0.4.0 (2020-10-28)
* Add support for all enumerables in `{:in, choices}` instead of just lists. You can now do things such as `{:in, 1..10}`.
* Deprecate the `:rename_to` schema option and emit a warning when used.
* Remove the `{:one_of, choices}` type which was deprecated in v0.3.3.
## v0.3.7 (2021-09-11)
* Add `NimbleOptions.new!/1` to validate the schema once.
## v0.3.6 (2021-07-13)
* Add `:float` type.
* Fix docs generation when custom key type has no keys.
## v0.3.5 (2020-11-09)
* Add support for the `{:list, subtype}` type.
## v0.3.4 (2020-11-05)
* Support nested schemas in the `{:or, subtypes}` type as `{:or, [:string, keyword_list: [enabled: [type: :boolean]]]}`.
* Improve validation of the return value of `{:custom, module, function, args}` functions.
* Support options in `NimbleOptions.docs/2`. For now only the `:nest_level` option is supported.
## v0.3.3 (2020-11-02)
* Add the `{:or, subtypes}` type.
* Deprecate the `{:one_of, choices}` and replace it with `{:in, choices}`. Using `{:one_of, choices}` emits a warning now.
## v0.3.2 (2020-10-26)
* Fix a small bug with docs for nested schemas.
## v0.3.1 (2020-10-25)
* Return `:key` and `:value` on `%NimbleOptions.ValidationError{}` to allow programmatic use of errors.
* Validate default values according to the specified type.
## v0.3.0 (2020-06-14)
* **Breaking change**: return `{:error, %NimbleOptions.ValidationError{}}` tuples when there's a validation error in `NimbleOptions.validate/2` instead of `{:error, message}` (with `message` being a string). You can use `Exception.message/1` to turn the `NimbleOptions.ValidationError` struct into a string.
* Add the `:pid` type.
## v0.2.1 (2020-05-08)
* Add `NimbleOptions.validate!/2`.
## v0.2.0 (2020-04-11)
* Change the behavior of `NimbleOptions.docs/1` to accept a normal schema and produce documentation for that.
* Add support for `doc: false` as a schema option to hide an option or an option and its subsection.
## v0.1.0 (2020-04-07)
* First release.

View File

@@ -0,0 +1,177 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

View File

@@ -0,0 +1,93 @@
# NimbleOptions
[![hex.pm badge](https://img.shields.io/badge/Package%20on%20hex.pm-informational)](https://hex.pm/packages/nimble_options)
[![Documentation badge](https://img.shields.io/badge/Documentation-ff69b4)][docs]
[![CI](https://github.com/dashbitco/nimble_options/actions/workflows/main.yml/badge.svg)](https://github.com/dashbitco/nimble_options/actions/workflows/main.yml)
[![Coverage Status](https://coveralls.io/repos/github/dashbitco/nimble_options/badge.svg?branch=master)](https://coveralls.io/github/dashbitco/nimble_options?branch=master)
[Online Documentation][docs].
A tiny library for validating and documenting high-level options.
This library allows you to validate options based on a definition.
A definition is a keyword list specifying how the options you want
to validate should look like:
```elixir
definition = [
connections: [
type: :non_neg_integer,
default: 5
],
url: [
type: :string,
required: true
]
]
```
Now you can validate options through `NimbleOptions.validate/2`:
```elixir
options = [url: "https://example.com"]
NimbleOptions.validate(options, definition)
#=> {:ok, [url: "https://example.com", connections: 5]}
```
If the options don't match the definition, an error is returned:
```elixir
NimbleOptions.validate([connections: 3], definition)
{:error,
%NimbleOptions.ValidationError{
keys_path: [],
message: "required option :url not found, received options: [:connections]"
}}
```
`NimbleOptions` is also capable of automatically generating
documentation for a definition by calling `NimbleOptions.docs/1`
with your definition.
## Installation
You can install `nimble_options` by adding it to your list of
dependencies in `mix.exs`:
```elixir
def deps do
[
{:nimble_options, "~> 1.0"}
]
end
```
## Nimble*
All nimble libraries by Dashbit:
* [NimbleCSV](https://github.com/dashbitco/nimble_csv) - simple and fast CSV parsing
* [NimbleOptions](https://github.com/dashbitco/nimble_options) - tiny library for validating and documenting high-level options
* [NimbleParsec](https://github.com/dashbitco/nimble_parsec) - simple and fast parser combinators
* [NimblePool](https://github.com/dashbitco/nimble_pool) - tiny resource-pool implementation
* [NimblePublisher](https://github.com/dashbitco/nimble_publisher) - a minimal filesystem-based publishing engine with Markdown support and code highlighting
* [NimbleTOTP](https://github.com/dashbitco/nimble_totp) - tiny library for generating time-based one time passwords (TOTP)
## License
Copyright 2020 Dashbit
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
> https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
[docs]: https://hexdocs.pm/nimble_options

View File

@@ -0,0 +1,16 @@
{<<"links">>,
[{<<"GitHub">>,<<"https://github.com/dashbitco/nimble_options">>}]}.
{<<"name">>,<<"nimble_options">>}.
{<<"version">>,<<"1.1.1">>}.
{<<"description">>,
<<"A tiny library for validating and documenting high-level options">>}.
{<<"elixir">>,<<"~> 1.9">>}.
{<<"app">>,<<"nimble_options">>}.
{<<"licenses">>,[<<"Apache-2.0">>]}.
{<<"requirements">>,[]}.
{<<"files">>,
[<<"lib">>,<<"lib/nimble_options">>,<<"lib/nimble_options/docs.ex">>,
<<"lib/nimble_options/validation_error.ex">>,<<"lib/nimble_options.ex">>,
<<".formatter.exs">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE.md">>,
<<"CHANGELOG.md">>]}.
{<<"build_tools">>,[<<"mix">>]}.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,301 @@
defmodule NimbleOptions.Docs do
@moduledoc false
def generate(schema, options) when is_list(schema) and is_list(options) do
nest_level = Keyword.get(options, :nest_level, 0)
{docs, sections, _level} = build_docs(schema, {[], [], nest_level})
to_string([Enum.reverse(docs), Enum.reverse(sections)])
end
# If the schema is a function, we want to not show anything (it's a recursive
# function) and "back up" one level since when we got here we already
# increased the level by one.
defp build_docs(fun, {docs, sections, level}) when is_function(fun) do
{docs, sections, level - 1}
end
defp build_docs(schema, {docs, sections, level} = acc) do
if schema[:*] do
build_docs(schema[:*][:keys], acc)
else
Enum.reduce(schema || [], {docs, sections, level}, &maybe_option_doc/2)
end
end
defp build_docs_with_subsection(subsection, schema, {docs, sections, level}) do
subsection = String.trim_trailing(subsection, "\n") <> "\n\n"
{item_docs, sections, _level} = build_docs(schema, {[], sections, 0})
item_section = [subsection | Enum.reverse(item_docs)]
{docs, [item_section | sections], level}
end
defp maybe_option_doc({key, schema}, acc) do
if schema[:doc] == false do
acc
else
option_doc({key, schema}, acc)
end
end
defp option_doc({key, schema}, {docs, sections, level}) do
type_str = if type_str = get_type_str(schema), do: " #{type_str}"
desc_indent = String.duplicate(" ", level + 1)
description =
get_required_str(schema)
|> get_deprecated_str(schema)
|> get_doc_str(schema)
|> get_default_str(schema)
|> case do
nil -> ""
parts -> indent_doc(" - " <> parts, desc_indent)
end
doc = [String.duplicate(" ", level), "* `#{inspect(key)}`#{type_str}", description, "\n\n"]
docs = [IO.iodata_to_binary(doc) | docs]
cond do
schema[:keys] && schema[:subsection] ->
build_docs_with_subsection(schema[:subsection], schema[:keys], {docs, sections, level})
schema[:keys] ->
{docs, sections, _level} = build_docs(schema[:keys], {docs, sections, level + 1})
{docs, sections, level}
true ->
{docs, sections, level}
end
end
defp space_concat(left, nil), do: left
defp space_concat(nil, right), do: right
defp space_concat(left, right), do: left <> " " <> right
defp get_required_str(schema) do
if schema[:required], do: "Required."
end
defp get_deprecated_str(prev_str, schema) do
space_concat(
prev_str,
schema[:deprecated] && "*This option is deprecated. #{String.trim(schema[:deprecated])}*"
)
end
defp get_doc_str(prev_str, schema) do
space_concat(prev_str, schema[:doc] && String.trim(schema[:doc]))
end
defp get_default_str(prev_str, schema) do
if Keyword.has_key?(schema, :default) do
default_str = "The default value is `#{inspect(schema[:default])}`."
# If the documentation contains multiple lines,
# the default must be in a trailing line.
if prev_str && String.contains?(prev_str, ["\r\n", "\n\n"]) do
prev_str <> "\n\n" <> default_str
else
space_concat(prev_str, default_str)
end
else
prev_str
end
end
defp get_type_str(schema) do
str =
case Keyword.fetch(schema, :type_doc) do
{:ok, false} -> nil
{:ok, type_doc} when is_binary(type_doc) -> type_doc
:error -> get_raw_type_str(schema[:type])
end
if str do
"(#{str})"
end
end
# Only shows types when they are concise.
defp get_raw_type_str(nil), do: nil
defp get_raw_type_str({:custom, _mod, _fun, _args}), do: nil
defp get_raw_type_str(:mfa), do: nil
defp get_raw_type_str(:mod_arg), do: nil
defp get_raw_type_str({:or, _values}), do: nil
defp get_raw_type_str({:in, _}), do: nil
defp get_raw_type_str({:fun, arity}), do: "function of arity #{arity}"
defp get_raw_type_str(:any), do: "`t:term/0`"
defp get_raw_type_str(:reference), do: "`t:reference/0`"
defp get_raw_type_str(:pid), do: "`t:pid/0`"
defp get_raw_type_str(:timeout), do: "`t:timeout/0`"
defp get_raw_type_str(:boolean), do: "`t:boolean/0`"
defp get_raw_type_str(:atom), do: "`t:atom/0`"
defp get_raw_type_str(:integer), do: "`t:integer/0`"
defp get_raw_type_str(:non_neg_integer), do: "`t:non_neg_integer/0`"
defp get_raw_type_str(:pos_integer), do: "`t:pos_integer/0`"
defp get_raw_type_str(:float), do: "`t:float/0`"
defp get_raw_type_str(:string), do: "`t:String.t/0`"
defp get_raw_type_str(:keyword_list), do: "`t:keyword/0`"
defp get_raw_type_str(:non_empty_keyword_list), do: "non-empty `t:keyword/0`"
defp get_raw_type_str({:map, _keys}), do: "`t:map/0`"
defp get_raw_type_str({:keyword_list, _keys}), do: "`t:keyword/0`"
defp get_raw_type_str({:non_empty_keyword_list, _keys}), do: "non-empty `t:keyword/0`"
defp get_raw_type_str(:map), do: "`t:map/0`"
defp get_raw_type_str({:struct, struct_type}), do: "struct of type `#{inspect(struct_type)}`"
defp get_raw_type_str({:list, subtype}) do
if subtype_str = get_raw_type_str(subtype), do: "list of #{subtype_str}"
end
defp get_raw_type_str({:map, key_type, value_type}) do
with key_type_str when is_binary(key_type_str) <- get_raw_type_str(key_type),
value_type_str when is_binary(value_type_str) <- get_raw_type_str(value_type) do
"map of #{key_type_str} keys and #{value_type_str} values"
end
end
defp get_raw_type_str({:tuple, value_types}) do
value_types =
value_types
|> Enum.map(&get_raw_type_str/1)
|> Enum.join(", ")
"tuple of #{value_types} values"
end
defp indent_doc(text, indent) do
[head | tail] = String.split(text, ["\r\n", "\n"])
tail =
Enum.map(tail, fn
"" -> "\n"
str -> [?\n, indent, str]
end)
[head | tail]
end
def schema_to_spec(schema) do
schema
|> Enum.map(fn {key, opt_schema} ->
typespec =
Keyword.get_lazy(opt_schema, :type_spec, fn -> type_to_spec(opt_schema[:type]) end)
quote do: {unquote(key), unquote(typespec)}
end)
|> unionize_quoted()
end
defp type_to_spec(type) do
case type do
:any ->
quote(do: term())
:integer ->
quote(do: integer())
:non_neg_integer ->
quote(do: non_neg_integer())
:pos_integer ->
quote(do: pos_integer())
:atom ->
quote(do: atom())
:float ->
quote(do: float())
:boolean ->
quote(do: boolean())
:pid ->
quote(do: pid())
:reference ->
quote(do: reference())
:timeout ->
quote(do: timeout())
:string ->
quote(do: binary())
:mfa ->
quote(do: {module(), atom(), [term()]})
:mod_arg ->
quote(do: {module(), [term()]})
:keyword_list ->
quote(do: keyword())
{:keyword_list, _keys} ->
quote(do: keyword())
:non_empty_keyword_list ->
quote(do: keyword())
{:non_empty_keyword_list, _keys} ->
quote(do: keyword())
nil ->
quote(do: nil)
:map ->
quote(do: map())
{:map, key_type, value_type} ->
quote(
do: %{optional(unquote(type_to_spec(key_type))) => unquote(type_to_spec(value_type))}
)
{:fun, arity} ->
function_spec(arity)
{:in, %Range{first: first, last: last} = range} ->
# TODO: match on first..last//1 when we depend on Elixir 1.12+
if Map.get(range, :step) in [nil, 1] do
quote(do: unquote(first)..unquote(last))
else
quote(do: term())
end
{:in, _choices} ->
quote(do: term())
{:custom, _mod, _fun, _args} ->
quote(do: term())
{:list, subtype} ->
quote(do: [unquote(type_to_spec(subtype))])
{:or, subtypes} ->
subtypes |> Enum.map(&type_to_spec/1) |> unionize_quoted()
{:struct, _struct_name} ->
quote(do: struct())
{:tuple, tuple_types} ->
case Enum.map(tuple_types, &type_to_spec/1) do
[type1, type2] -> quote(do: {unquote(type1), unquote(type2)})
types -> quote do: {unquote_splicing(types)}
end
end
end
defp function_spec(arity) do
args = List.duplicate(quote(do: term()), arity)
quote do
unquote_splicing(args) -> term()
end
end
defp unionize_quoted(specs) do
specs
|> Enum.reverse()
|> Enum.reduce(&quote(do: unquote(&1) | unquote(&2)))
end
end

View File

@@ -0,0 +1,43 @@
defmodule NimbleOptions.ValidationError do
@moduledoc """
An error that is returned (or raised) when options are invalid.
Since this is an exception, you can either raise it directly with `raise/1`
or turn it into a message string with `Exception.message/1`.
See [`%NimbleOptions.ValidationError{}`](`__struct__/0`) for documentation on the fields.
"""
@type t() :: %__MODULE__{
key: atom(),
keys_path: [atom()],
value: term()
}
@doc """
The error struct.
Only the following documented fields are considered public. All other fields are
considered private and should not be referenced:
* `:key` (`t:atom/0`) - The key that did not successfully validate.
* `:keys_path` (list of `t:atom/0`) - If the key is nested, this is the path to the key.
* `:value` (`t:term/0`) - The value that failed to validate. This field is `nil` if there
was no value provided.
"""
defexception [:message, :key, :value, keys_path: []]
@impl true
def message(%__MODULE__{message: message, keys_path: keys_path}) do
suffix =
case keys_path do
[] -> ""
keys -> " (in options #{inspect(keys)})"
end
message <> suffix
end
end

View File

@@ -0,0 +1,66 @@
defmodule NimbleOptions.MixProject do
use Mix.Project
@version "1.1.1"
@repo_url "https://github.com/dashbitco/nimble_options"
def project do
[
app: :nimble_options,
version: @version,
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
deps: deps(),
# Tests
test_coverage: [tool: ExCoveralls],
# Hex
package: package(),
description: "A tiny library for validating and documenting high-level options",
# Docs
name: "NimbleOptions",
docs: docs()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: []
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# excoverals uses CAStore to push results via HTTP.
{:castore, "~> 1.0.0", only: :test},
{:ex_doc, ">= 0.19.0", only: :dev},
{:excoveralls, "~> 0.18.0", only: :test}
]
end
defp package do
[
maintainers: ["Andrea Leopardi", "José Valim", "Marlus Saraiva"],
licenses: ["Apache-2.0"],
links: %{"GitHub" => @repo_url}
]
end
defp docs do
[
main: "NimbleOptions",
extras: [
"CHANGELOG.md": [title: "Changelog"],
"LICENSE.md": [title: "License"]
],
source_ref: "v#{@version}",
source_url: @repo_url,
formatters: ["html"],
skip_undefined_reference_warnings_on: ["CHANGELOG.md"]
]
end
end