packages feed

config-schema 0.3.0.0 → 0.3.1.0

raw patch · 4 files changed

+44/−26 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Revision history for config-schema +## 0.3.1.0  -- 2017-05-16++* Allow `generateDocs` to work on any ValueSpec, rather than+  top-level empty-named section specs.+ ## 0.3.0.0  -- 2017-05-09  * Added "association list" specifications
README.md view
@@ -13,14 +13,13 @@  ```haskell {-# Language OverloadedStrings, ApplicativeDo #-}- module Example where  import qualified Data.Text as Text-import qualified Data.Text.IO as Text import           Data.Text (Text) import           Data.Monoid ((<>)) import           Data.Functor.Alt ((<!>))+import           Data.List.NonEmpty (NonEmpty)  import           Config import           Config.Schema@@ -34,15 +33,17 @@   \   * name: \"Bob\"         \n\   \   * name: \"Tom\"         \n" -exampleValue :: Value+exampleValue :: Value Position Right exampleValue = parse exampleFile  exampleSpec :: ValueSpecs Text exampleSpec = sectionsSpec "" $   do name  <- reqSection  "name" "Full name"      age   <- reqSection  "age"  "Age of user"-     happy <- optSection' "happy" "Current happiness status" yesOrNo-     kids  <- reqSection' "kids"  "All children" (oneOrList kidSpec)+     happy <- optSection' "happy" yesOrNo+              "Current happiness status"+     kids  <- reqSection' "kids"  (oneOrList kidSpec)+              "All children's names"       return $        let happyText = case happy of Just True  -> " and is happy"@@ -65,9 +66,9 @@   printDoc :: IO ()-printDoc = Text.putStr (generateDocs exampleSpec)+printDoc = print (generateDocs exampleSpec) -- *Example> printDoc--- Configuration file fields:+-- Top-level configuration file fields: --     name: REQUIRED text --        Full name --     age: REQUIRED integer@@ -81,7 +82,7 @@ --     name: REQUIRED text --        Kid's name -example :: Either [LoadError] Text+example :: Either (NonEmpty LoadError) Text example = loadValue exampleSpec exampleValue -- *Example> exampleVal -- Right "Johny Appleseed is 99 years old and has kids Bob, Tom and is happy"
config-schema.cabal view
@@ -1,5 +1,5 @@ name:                config-schema-version:             0.3.0.0+version:             0.3.1.0 synopsis:            Schema definitions for the config-value package description:         This package makes it possible to defined schemas for use when                      loading configuration files using the config-value format.@@ -31,7 +31,7 @@                         free           >=4.12  && <4.13,                         kan-extensions >=5.0.2 && <5.1,                         pretty         >=1.1.3 && <1.2,-                        semigroupoids  >=5.2   && <5.3,+                        semigroupoids  >=5.1   && <5.3,                         text           >=1.2   && <1.3,                         transformers   >=0.5   && <0.6   hs-source-dirs:       src
src/Config/Schema/Docs.hs view
@@ -24,7 +24,7 @@  generateDocs configSpec --- Configuration file fields:+-- Top-level configuration file fields: --     username: REQUIRED text --        Name used to login --     attempts: integer@@ -37,33 +37,43 @@   ) where  import           Data.List (intersperse)+import           Data.List.NonEmpty (NonEmpty((:|))) import           Data.Map (Map) import qualified Data.Map as Map import           Data.Text (Text) import qualified Data.Text as Text-import           Text.PrettyPrint (Doc, text, ($+$), (<>), (<+>), nest, empty, hsep)+import           Text.PrettyPrint (Doc, fsep, text, ($+$), (<>), (<+>), nest, empty, hsep)  import           Config.Schema.Spec --- | Default documentation generator. This generator is specifically--- for configuration specifications where the top-level specification--- is named with the empty string (@""@).+-- | Default documentation generator. generateDocs :: ValueSpecs a -> Doc-generateDocs spec-  = vcat'-  $ txt "Configuration file fields:"-  : nest 4 top-  : concatMap sectionLines (Map.toList m')+generateDocs spec = vcat' docLines   where-    topname = ""-    Just top = Map.lookup topname m-    (m,"") = runDocBuilder (valuesDoc spec)-    m' = Map.delete topname m-     sectionLines :: (Text, Doc) -> [Doc]     sectionLines (name, fields) = [text "", txt name, nest 4 fields] +    (topMap, topDoc) = runDocBuilder (valuesDoc spec) +    docLines =+      case runValueSpecs_ (pure . SomeSpec) spec of+        -- single, top-level sections spec+        SomeSpec (SectionSpecs name _) :| []+          | Just top <- Map.lookup name topMap ->+              txt "Top-level configuration file fields:" :+              nest 4 top :+              concatMap sectionLines (Map.toList (Map.delete name topMap))++        -- otherwise+        _ -> txt "Top-level configuration file format:" :+             nest 4 topDoc :+             concatMap sectionLines (Map.toList topMap)+++-- | Forget the type of the value spec+data SomeSpec where SomeSpec :: ValueSpec a -> SomeSpec++ -- | Compute the documentation for a list of sections, store the -- documentation in the sections map and return the name of the section. sectionsDoc :: Text -> SectionSpecs a -> DocBuilder Doc@@ -79,7 +89,9 @@   where     aux req name desc val =       txt name <> ":" <+> req <+> val $+$-      if Text.null desc then empty else nest 4 (txt desc)+      if Text.null desc+        then empty+        else nest 4 (fsep (txt <$> Text.splitOn " " desc)) -- line wrap logic   -- | Compute the documentation line for a particular value specification.