{"id":24076686,"url":"https://github.com/apirogov/yaml-conf","last_synced_at":"2025-02-26T23:15:52.747Z","repository":{"id":138158541,"uuid":"102210526","full_name":"apirogov/yaml-conf","owner":"apirogov","description":"Simple library to turn record types into a flexible YAML-based configuration","archived":false,"fork":false,"pushed_at":"2017-09-04T18:48:03.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-09T20:00:55.271Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apirogov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-02T16:52:15.000Z","updated_at":"2017-09-04T19:18:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"44d3a62d-97da-4b54-a2e0-96fc71a2b2ec","html_url":"https://github.com/apirogov/yaml-conf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apirogov%2Fyaml-conf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apirogov%2Fyaml-conf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apirogov%2Fyaml-conf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apirogov%2Fyaml-conf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apirogov","download_url":"https://codeload.github.com/apirogov/yaml-conf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240947660,"owners_count":19883031,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-09T20:00:14.715Z","updated_at":"2025-02-26T23:15:52.741Z","avatar_url":"https://github.com/apirogov.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yaml-conf  [![Build Status](https://travis-ci.org/apirogov/yaml-conf.svg)](https://travis-ci.org/apirogov/yaml-conf)\n\u003c!---\n[![Hackage version](https://img.shields.io/hackage/v/cairo-canvas.svg?style=flat)](https://hackage.haskell.org/package/cairo-canvas)\n--\u003e\n\nYou are looking for a configuration solution that:\n\n* works with your own record-style datatype?\n* does not require much additional work?\n* integrates well with argument parsing?\n* allows to obtain a configuration merging settings from multiple sources?\n\nThen look no more! Look at this example program:\n\n```haskell\n{-# LANGUAGE TemplateHaskell, MultiParamTypeClasses, FunctionalDependencies #-}\nmodule Main where\n\nimport Data.Monoid\nimport Options.Applicative\nimport Data.Default\nimport Data.Yaml.Conf\n\ndata SubConf = SubConf {\n    _uno :: Int\n  , _dos :: String\n  } deriving (Show)\n---- only four magic lines required per Conf type:\ninstance Default SubConf where\n  def = SubConf 0 \"default\"\nmakeConfig ''SubConf\nderiveConfigJSON ''SubConf\n----\n\n\ndata TestConf = TestConf {\n    _foo :: Bool\n  , _bar :: SubConf\n  } deriving (Show)\n---- for the main configuration type too:\ninstance Default TestConf where\n  def = TestConf False def\nmakeConfig ''TestConf\nderiveConfigJSON ''TestConf\n----\n\n-- yaml-conf can take any action that returns a configuration as input...\nargsParser :: IO TestConf\nargsParser = execParser $ info (parseArgs \u003c**\u003e helper)\n             (fullDesc \u003c\u003e progDesc \"yaml-conf demo\")\n\n-- ... so you can provide for example your optparse-applicative parser,\n-- after ensuring that uses the specified default values.\nparseArgs :: Parser TestConf\nparseArgs = TestConf\n  \u003c$\u003e switch (long \"foo\" \u003c\u003e short 'f' \u003c\u003e help \"foo blub\")\n  \u003c*\u003e (SubConf\n        \u003c$\u003e option auto (long \"uno\" \u003c\u003e short 'u' \u003c\u003e value (_uno def))\n        \u003c*\u003e option str  (long \"dos\" \u003c\u003e short 'd' \u003c\u003e value (_dos def))\n      )\n\nmain :: IO ()\nmain = do\n  let progname = \"yaml-conf-demo\"\n  let confname = \"config\"\n\n  putStrLn \"Default configuration:\"\n  print (def::TestConf)\n\n  putStrLn \"Default file locations (descending priority):\"\n  print =\u003c\u003c defaultConfPaths progname confname\n\n  sources \u003c- addConfSource argsParser \u003c$\u003e defaultConfSources progname confname\n\n  putStrLn \"Loaded configuration diffs (ascending priority):\"\n  print =\u003c\u003c sequence sources\n\n  putStrLn \"Resulting Conf:\"\n  conf \u003c- loadConf sources\n  print conf\n```\n\nThe program defines a main configuration record type, TestConf,\nand a nested sub-configuration, SubConf. The only thing required from you is to\nprovide default instances and issue the two Template Haskell incantations. The\nrest ist done for you automatically!\n\nNow you can obtain a configuration stitched together from multiple sources,\nincluding multiple locations of files and e.g. an optparse-applicative parser. The\nonly thing that you need to buy into is the fact that the configuration files\nare in YAML-format. A valid configuration for the program above looks like this:\n\n```\nfoo: true\nbar:\n  dos: \"local override\"\n```\n\nYou can place such a configuration into e.g. `~/.config/yaml-conf-demo/config.yaml`.\nNotice, that each field of a record marked as a configuration is optional and can be omitted,\nyou just need to put values for fields you want to override from lower priority\nor the default configuration.\n\nFor a better understanding, just run this demo application and observe the output.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapirogov%2Fyaml-conf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapirogov%2Fyaml-conf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapirogov%2Fyaml-conf/lists"}