Skip to content

A tiny library for validating and documenting high-level MACRO options

License

Notifications You must be signed in to change notification settings

bcksl/macro_opts

 
 

Repository files navigation

MacroOpts

Hex Hex Docs Downloads Build Status Coverage Status License GitHub Stars

Foreword

This library is a very direct port of NimbleOptions with additions/modifications to work with AST structures. Much credit goes to the authors of that library, particularly for producing such a comprehensive test suite, which provided a great baseline for MacroOpts.

MacroOpts also keeps the Apache 2.0 license of NimbleOptions. See the License section for details.

Online Documentation.

A tiny library for validating and documenting high-level macro 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:

definition = [
  connections: [
    type: :non_neg_integer,
    default: 5
  ],
  url: [
    type: :string,
    required: true
  ]
]

Now you can validate options through MacroOpts.validate/2:

options = [url: "https://example.com"]

MacroOpts.validate(options, definition)
#=> {:ok, [url: "https://example.com", connections: 5]}

If the options don't match the definition, an error is returned:

MacroOpts.validate([connections: 3], definition)
{:error,
 %MacroOpts.ValidationError{
   keys_path: [],
   message: "required option :url not found, received options: [:connections]"
 }}

MacroOpts is also capable of automatically generating documentation for a definition by calling MacroOpts.docs/1 with your definition.

Installation

You can install macro_opts by adding it to your list of dependencies in mix.exs:

def deps do
  [
    {:macro_opts, "~> 0.1.0"}
  ]
end

License

Modified work ("MacroOpts") Copyright 2023 bcksl Original work ("NimbleOptions") 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 in this directory at LICENSE.md or at

http://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.

About

A tiny library for validating and documenting high-level MACRO options

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%