salak 0.1.1 → 0.1.2
raw patch · 6 files changed
+26/−21 lines, 6 filesdep ~base
Dependency ranges changed: base
Files
- README.md +5/−0
- salak.cabal +2/−2
- src/Data/Salak.hs +10/−10
- src/Data/Salak/CommandLine.hs +1/−1
- src/Data/Salak/Types.hs +3/−3
- test/Spec.hs +5/−5
README.md view
@@ -1,1 +1,6 @@ # salak++[](https://hackage.haskell.org/package/salak)+++Configuration Loader for Production in Haskell.
salak.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 5c22b23921e52c02d6bfc91c02e5cd2945f51b95d388cd2e07e992173557b53e+-- hash: 82f2482ba7f49ee8ad36d437e333c17b1bbfe849d8d94af64aeb66a611d3a71c name: salak-version: 0.1.1+version: 0.1.2 synopsis: Configuration Loader description: Configuration Loader for Production in Haskell category: Library
src/Data/Salak.hs view
@@ -7,8 +7,8 @@ -- Stability: experimental -- Portability: portable ----- Configuration Loader for Production in Haskell. --- +-- Configuration Loader for Production in Haskell.+-- module Data.Salak( -- * How to use this library -- $use@@ -48,12 +48,12 @@ import System.Directory import System.FilePath ((</>)) --- | Initialize default properties from `CommandLine` and `Environment`. +-- | Initialize default properties from `CommandLine` and `Environment`. -- `CommandLine` use default parser. defaultProperties :: IO Properties defaultProperties = defaultProperties' defaultParseCommandLine --- | Initialize default properties from `CommandLine` and `Environment`. +-- | Initialize default properties from `CommandLine` and `Environment`. defaultProperties' :: ParseCommandLine -> IO Properties defaultProperties' dpc = makePropertiesFromCommandLine dpc empty@@ -71,7 +71,7 @@ -- > 4. Yaml file in current directory -- > 5. Yaml file in home directory ---defaultPropertiesWithFile +defaultPropertiesWithFile :: FileName -- ^ specify default config file name, can reset by config "salak.config.name" from `CommandLine` or `Environment`. -> IO Properties defaultPropertiesWithFile name = do@@ -92,9 +92,9 @@ -- $use--- --- | This library default a standard configuration load process. It can load properties from `CommandLine`, `Environment`, --- `JSON value` and `Yaml` files. They all load to the same format `Properties`. Earler property source has higher order +--+-- | This library default a standard configuration load process. It can load properties from `CommandLine`, `Environment`,+-- `JSON value` and `Yaml` files. They all load to the same format `Properties`. Earler property source has higher order -- to load property. For example: -- -- > CommandLine: --package.a.enabled=true@@ -111,13 +111,13 @@ -- > , dir :: Maybe Text -- > , ext :: Int -- > } deriving (Eq, Show)--- > +-- > -- > instance FromJSON Config where -- > parseJSON = withObject "Config" $ \v -> Config -- > <$> v .: "name" -- > <*> v .:? "dir" -- > <*> (fromMaybe 1 <$> v .:? "ext")--- +-- -- > main = do -- > p <- defaultPropertiesWithFile "salak.yml" -- > let Just config = lookup "salak.config" p :: Maybe Config
src/Data/Salak/CommandLine.hs view
@@ -10,7 +10,7 @@ -- | Default command line parsers. -- Use format:--- +-- -- > --KEY=VALUE -- -- For example:
src/Data/Salak/Types.hs view
@@ -52,11 +52,11 @@ empty = Properties [] [] -- | Split origin key by '.' to sub keys:--- +-- -- > "salak.config.name" -> ["salak","config","name"] -- > "" -> [] -- > "a..b" -> ["a","b"]--- +-- toKeys :: String -> [Key] toKeys = fmap pack . filter (not.null) . splitOneOf "." @@ -131,7 +131,7 @@ instance FromProperties Property where fromProperties (Properties (a:_) _) = OK a- fromProperties _ = Empty+ fromProperties _ = Empty instance {-# OVERLAPPABLE #-} FromProperties a => FromProperties [a] where fromProperties (Properties ps ms) =
test/Spec.hs view
@@ -10,7 +10,7 @@ import Data.Salak import Data.Salak.CommandLine import Data.Salak.Environment-import qualified Data.Salak.Property as P+import qualified Data.Salak.Types as P import Data.Text (Text, pack) import System.Environment import Test.Hspec@@ -19,7 +19,7 @@ spec :: Spec spec = do- describe "Data.Salak.Property" specProperty+ describe "Data.Salak.Types" specProperty shouldFail :: (HasCallStack, Show a, Eq a) => a -> a -> Expectation shouldFail f a = (f `shouldBe` a) `shouldThrow` anyErrorCall@@ -41,7 +41,7 @@ it "normal" $ do let p = empty print p- p `shouldBe` Node [] []+ p `shouldBe` Properties [] [] context "toKeys" $ do it "normal" $ do [] `shouldBe` toKeys ""@@ -54,8 +54,8 @@ k = toKeys "a.b" m = insert k p empty it "normal" $ do- insert [] p empty `shouldBe` Node [p] []- insert k p empty `shouldBe` Node [] [M.insert "a" (Node [] [M.insert "b" (Node [p] []) M.empty]) M.empty]+ insert [] p empty `shouldBe` Properties [p] []+ insert k p empty `shouldBe` Properties [] [M.insert "a" (Properties [] [M.insert "b" (Properties [p] []) M.empty]) M.empty] it "Reject replacement" $ do insert k (PStr "1") m `shouldBe` m context "lookup" $ do